Click here to Skip to main content
Licence CPOL
First Posted 26 Jun 2007
Views 27,553
Downloads 244
Bookmarked 30 times

Universal Web Services Consumer Using HTTP POST

By | 26 Jun 2007 | Article
Call Web Services methods without adding a web reference.

Screenshot - UniversalWSConsumer.gif

Introduction

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.

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

License

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

About the Author

Pramirez

Web Developer

Mexico Mexico

Member

I am Pedro Ramirez from mexico, work for www.sciodev.com, 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#.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalbug if you call a ws with no parameters Pinmemberbaileyk8313:57 15 Apr '09  
Generalnice Pinmemberfronjm0512:05 9 Aug '07  
GeneralResponse to user:fronjm05 PinmemberPramirez12:01 9 Aug '07  
GeneralRe: Response to user:fronjm05 Pinmemberfronjm053:59 16 Aug '07  
GeneralRe: Response to user:fronjm05 PinmemberPramirez5:11 16 Aug '07  
GeneralGreat article PinmemberMitchL5:53 10 Jul '07  
QuestionSOAP? Pinmemberroberto galbiati0:31 3 Jul '07  
AnswerRe: SOAP? PinmemberBPanic2:36 3 Jul '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.5.120517.1 | Last Updated 26 Jun 2007
Article Copyright 2007 by Pramirez
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid