Click here to Skip to main content
13,256,716 members (52,046 online)
Click here to Skip to main content
Add your own
alternative version


31 bookmarked
Posted 26 Jun 2007

Universal Web Services Consumer Using HTTP POST

, 26 Jun 2007
Rate this:
Please Sign up or sign in to vote.
Call Web Services methods without adding a web reference.

Screenshot - UniversalWSConsumer.gif


This article explains how to consume Web Services without adding a Web Reference to the project.

Using the code

Use the WSRequestHelper class to consume the Web Service. This has been tested on some public Web Services.


  • 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.


  • CallWebServiceReturnString: Call the Web Service and return the response as a string.
  • CallWebService: Call the Web Service and return the response as an 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 this with some Cold Fusion Web Services as well.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Mexico Mexico
I am Pedro Ramirez from mexico, work for, the company is located in Mexico, we do outsourcing and nearshore development, we are focused on SaaS nearshore development, I started with VB.Net, but now I am ambidextrous using VB.Net or C#.

You may also be interested in...


Comments and Discussions

Generalbug if you call a ws with no parameters Pin
baileyk8315-Apr-09 14:57
memberbaileyk8315-Apr-09 14:57 
Generalnice Pin
fronjm059-Aug-07 13:05
memberfronjm059-Aug-07 13:05 
GeneralResponse to user:fronjm05 Pin
Pramirez9-Aug-07 13:01
memberPramirez9-Aug-07 13:01 
GeneralRe: Response to user:fronjm05 Pin
fronjm0516-Aug-07 4:59
memberfronjm0516-Aug-07 4:59 
GeneralRe: Response to user:fronjm05 Pin
Pramirez16-Aug-07 6:11
memberPramirez16-Aug-07 6:11 
GeneralGreat article Pin
MitchL10-Jul-07 6:53
memberMitchL10-Jul-07 6:53 

Great article! Nice way to talk to unknown web services using simple types.

Great Job!
QuestionSOAP? Pin
roberto galbiati3-Jul-07 1:31
memberroberto galbiati3-Jul-07 1:31 
AnswerRe: SOAP? Pin
BPanic3-Jul-07 3:36
memberBPanic3-Jul-07 3:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 26 Jun 2007
Article Copyright 2007 by Pramirez
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid