Introduction
Consume Web Services without adding a Web Reference to the Project
Using the code
Use the WSRequestHelper class to consume the Web Service, Tested on some of this Public Web Services(http://www.xmethods.org/)
Properties
|
URL
|
The Url of the Web Service, example:http://localhost/Project.WS.Auth/AuthService.asmx |
|
Method
|
The Method to call, example:Login
|
|
Parameters
|
The Parameters needed for the Call
|
Methods
|
CallWebServiceReturnString
|
Call the Web Service and return the Respose as a String
|
|
CallWebService
|
Call the Web Service and return the Respose as a XML Document
|
Constructor for the Class
'The object that will manage the Soap Request
Dim SoapHelper As New WSRequestHelper(Me.txtWSDLAddress.Text, Me.txtMethod.Text)
'Calling the Web Service
Me.txtWSResponse.Text = SoapHelper.CallWebService().InnerText
Core of the WSRequestHelper Class
'Create the WebClient
Dim Request As New WebClient
'Set up the request
Request.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
Making the Call inside the class
'Request to the WS
Dim Req As WebClient = CreateRequest()
'Soap Message to send
Dim MessageToPost As String = CreateMessage()
Return Req.UploadString(Me.PostURL, "POST", MessageToPost)
'Request to the WS
Dim Req As WebClient = CreateRequest()
Points of Interest
The Call to the Web service uses HTTP Post for the request so, may be some Methods cannot be invoked with this approach, the code has not been tested with complex types.
To use Soap use the Runtime.Serialization.Formatters.SoapMessage Class, it works I have used with some Cold Fusion Web Services
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.