Buenas , Aqui veras como hacer un encapsulado de un asmx en una dll a traves del WSDL.exe que incorpora microsoft SDKs.
Para poder realizar el ejemplo correctamente deberás crear 2 proyectos en la misma solución; 1 para la dll y 2 otro para el formulario que llamara a esa dll tal y como se indica en el video.
Lo primero que deberás hacer es descargar en formato vb el servcio asmx a traves del Wsdl, para ello abre una consola de comandos localiza el wsdl.exe dentro de microsoft sdks y introduce el siguiente comando en la consola en la ruta :
wsdl http://soulsmakers.com/TEST.asmx /out:C:\<tudirectorio>\DLLPROXY.vb /language:vb
Una vez que lo tengas agregalo a tu proyecto dll y agrega las referencias system.web system.net y compilalo.
A continuación en tu proyecto de winforms agrega la referencia que has compilado y ya dispondrás de las funciones que tiene como referencia el webservice.
Mira el siguiente video donde te explico todos los pasos a seguir, y a continuación te dejo todo el codigo para que puedas tenerlo
Por si no pudiste descargar el vb del servicio aquí esta el código.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
Option Strict Off Option Explicit On Imports System Imports System.ComponentModel Imports System.Diagnostics Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Xml.Serialization ' 'Este código fuente fue generado automáticamente por wsdl, Versión=2.0.50727.3038. ' '''<remarks/> <System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038"), _ System.Diagnostics.DebuggerStepThroughAttribute(), _ System.ComponentModel.DesignerCategoryAttribute("code"), _ System.Web.Services.WebServiceBindingAttribute(Name:="TESTSoap", [Namespace]:="http://tempuri.org/")> _ Partial Public Class TEST Inherits System.Web.Services.Protocols.SoapHttpClientProtocol Private DimeHolaOperationCompleted As System.Threading.SendOrPostCallback Private DimeHolaEnInglesOperationCompleted As System.Threading.SendOrPostCallback '''<remarks/> Public Sub New() MyBase.New Me.Url = "http://soulsmakers.com/TEST.asmx" End Sub '''<remarks/> Public Event DimeHolaCompleted As DimeHolaCompletedEventHandler '''<remarks/> Public Event DimeHolaEnInglesCompleted As DimeHolaEnInglesCompletedEventHandler '''<remarks/> <System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/DimeHola", RequestNamespace:="http://tempuri.org/", ResponseNamespace:="http://tempuri.org/", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _ Public Function DimeHola() As String Dim results() As Object = Me.Invoke("DimeHola", New Object(-1) {}) Return CType(results(0),String) End Function '''<remarks/> Public Function BeginDimeHola(ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult Return Me.BeginInvoke("DimeHola", New Object(-1) {}, callback, asyncState) End Function '''<remarks/> Public Function EndDimeHola(ByVal asyncResult As System.IAsyncResult) As String Dim results() As Object = Me.EndInvoke(asyncResult) Return CType(results(0),String) End Function '''<remarks/> Public Overloads Sub DimeHolaAsync() Me.DimeHolaAsync(Nothing) End Sub '''<remarks/> Public Overloads Sub DimeHolaAsync(ByVal userState As Object) If (Me.DimeHolaOperationCompleted Is Nothing) Then Me.DimeHolaOperationCompleted = AddressOf Me.OnDimeHolaOperationCompleted End If Me.InvokeAsync("DimeHola", New Object(-1) {}, Me.DimeHolaOperationCompleted, userState) End Sub Private Sub OnDimeHolaOperationCompleted(ByVal arg As Object) If (Not (Me.DimeHolaCompletedEvent) Is Nothing) Then Dim invokeArgs As System.Web.Services.Protocols.InvokeCompletedEventArgs = CType(arg,System.Web.Services.Protocols.InvokeCompletedEventArgs) RaiseEvent DimeHolaCompleted(Me, New DimeHolaCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)) End If End Sub '''<remarks/> <System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/DimeHolaEnIngles", RequestNamespace:="http://tempuri.org/", ResponseNamespace:="http://tempuri.org/", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _ Public Function DimeHolaEnIngles() As String Dim results() As Object = Me.Invoke("DimeHolaEnIngles", New Object(-1) {}) Return CType(results(0),String) End Function '''<remarks/> Public Function BeginDimeHolaEnIngles(ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult Return Me.BeginInvoke("DimeHolaEnIngles", New Object(-1) {}, callback, asyncState) End Function '''<remarks/> Public Function EndDimeHolaEnIngles(ByVal asyncResult As System.IAsyncResult) As String Dim results() As Object = Me.EndInvoke(asyncResult) Return CType(results(0),String) End Function '''<remarks/> Public Overloads Sub DimeHolaEnInglesAsync() Me.DimeHolaEnInglesAsync(Nothing) End Sub '''<remarks/> Public Overloads Sub DimeHolaEnInglesAsync(ByVal userState As Object) If (Me.DimeHolaEnInglesOperationCompleted Is Nothing) Then Me.DimeHolaEnInglesOperationCompleted = AddressOf Me.OnDimeHolaEnInglesOperationCompleted End If Me.InvokeAsync("DimeHolaEnIngles", New Object(-1) {}, Me.DimeHolaEnInglesOperationCompleted, userState) End Sub Private Sub OnDimeHolaEnInglesOperationCompleted(ByVal arg As Object) If (Not (Me.DimeHolaEnInglesCompletedEvent) Is Nothing) Then Dim invokeArgs As System.Web.Services.Protocols.InvokeCompletedEventArgs = CType(arg,System.Web.Services.Protocols.InvokeCompletedEventArgs) RaiseEvent DimeHolaEnInglesCompleted(Me, New DimeHolaEnInglesCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)) End If End Sub '''<remarks/> Public Shadows Sub CancelAsync(ByVal userState As Object) MyBase.CancelAsync(userState) End Sub End Class '''<remarks/> <System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")> _ Public Delegate Sub DimeHolaCompletedEventHandler(ByVal sender As Object, ByVal e As DimeHolaCompletedEventArgs) '''<remarks/> <System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038"), _ System.Diagnostics.DebuggerStepThroughAttribute(), _ System.ComponentModel.DesignerCategoryAttribute("code")> _ Partial Public Class DimeHolaCompletedEventArgs Inherits System.ComponentModel.AsyncCompletedEventArgs Private results() As Object Friend Sub New(ByVal results() As Object, ByVal exception As System.Exception, ByVal cancelled As Boolean, ByVal userState As Object) MyBase.New(exception, cancelled, userState) Me.results = results End Sub '''<remarks/> Public ReadOnly Property Result() As String Get Me.RaiseExceptionIfNecessary Return CType(Me.results(0),String) End Get End Property End Class '''<remarks/> <System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")> _ Public Delegate Sub DimeHolaEnInglesCompletedEventHandler(ByVal sender As Object, ByVal e As DimeHolaEnInglesCompletedEventArgs) '''<remarks/> <System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038"), _ System.Diagnostics.DebuggerStepThroughAttribute(), _ System.ComponentModel.DesignerCategoryAttribute("code")> _ Partial Public Class DimeHolaEnInglesCompletedEventArgs Inherits System.ComponentModel.AsyncCompletedEventArgs Private results() As Object Friend Sub New(ByVal results() As Object, ByVal exception As System.Exception, ByVal cancelled As Boolean, ByVal userState As Object) MyBase.New(exception, cancelled, userState) Me.results = results End Sub '''<remarks/> Public ReadOnly Property Result() As String Get Me.RaiseExceptionIfNecessary Return CType(Me.results(0),String) End Get End Property End Class |
Y las llamadas de los botones del ejemplo
1 2 3 4 5 6 7 8 9 |
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim srv As New PROXYDLL.TEST MsgBox(srv.DimeHola) End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim srv As New PROXYDLL.TEST MsgBox(srv.DimeHolaEnIngles) End Sub |
Si te ha gustado suscribete a mi canal de youtube y en la web para obtener mas actualizaciones de contenidos un saludo a tod@s
Y por si te interesa hacer: Crear un asmx con acceso a datos