Click here to Skip to main content
6,822,123 members and growing! (16,532 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Beginner License: The Code Project Open License (CPOL)

Universal Web Services Consumer using HTTP POST

By Pramirez

Call Web Services's Method without add a web reference
VB8.0, Windows, .NET2.0, ASP.NET, WebForms, VS2005, Dev
Posted:26 Jun 2007
Views:21,391
Bookmarked:27 times
Unedited contribution
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
7 votes for this article.
Popularity: 2.54 Rating: 3.00 out of 5
2 votes, 28.6%
1
1 vote, 14.3%
2

3

4
4 votes, 57.1%
5
Screenshot - UniversalWSConsumer.gif

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


License

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

About the Author

Pramirez


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#.
Occupation: Web Developer
Location: Mexico Mexico

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
Generalbug if you call a ws with no parameters Pinmemberbaileyk8314:57 15 Apr '09  
Generalnice Pinmemberfronjm0513:05 9 Aug '07  
GeneralResponse to user:fronjm05 PinmemberPramirez13:01 9 Aug '07  
GeneralRe: Response to user:fronjm05 Pinmemberfronjm054:59 16 Aug '07  
GeneralRe: Response to user:fronjm05 PinmemberPramirez6:11 16 Aug '07  
GeneralGreat article PinmemberMitchL6:53 10 Jul '07  
GeneralSOAP? Pinmemberroberto galbiati1:31 3 Jul '07  
GeneralRe: SOAP? PinmemberBPanic3:36 3 Jul '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 26 Jun 2007
Editor:
Copyright 2007 by Pramirez
Everything else Copyright © CodeProject, 1999-2010
Web18 | Advertise on the Code Project