Click here to Skip to main content
Licence CPOL
First Posted 14 Feb 2005
Views 115,653
Bookmarked 21 times

Consume WebService Using SOAP

By | 27 Feb 2005 | Article
Consume WebService Using SOAP

Introduction

Web Services are thought of as a means to provide easily accessible services over a network. We can use VS.NET IDE to create a Web Service.

While there are different techniques to communicate with a Web Services, SOAP is regarded as the actual standard. SOAP messages are being sent to service endpoints. This can simply be SOAP over HTTP.

Information Regarding Exsiting Web Service

.Asmx file for that WebService (URL):

http://localhost/AddNumbers/Service1.asmx

WSDL URL:

http://localhost/AddNumbers/Service1.asmx ?wsdl

Namespace of web service:

http://localhost/wwwroot/addnumbers/Service1

Method:

int AddTwoNumbers (int, int)

Class:

Service1

Steps For Consuming Web Service Using SOAP

  1. Start a new ASP.NET web application.
  2. Install msxml.msi, then click on “Add reference “ and then select “Interop.MSXML2.dll” and click on add.

    You can download the English version of the msxml.msi install file via this link: http://download.microsoft.com/download/7/a/7/7a72ca2e-39cc-4600-ab36-bf3fea876a65/msxml3.msi.

  3. Create one label to display result (ID = lablel1).
  4. Declare objXMLHttp of type MSXML2.ServerXMLHTTP40.
          Protected MSXML2.ServerXMLHTTP40 objXMLHttp 
  5. Declare one string strSoapEnvelope which contains soap request.
          string strSoapEnvelope= “”;
  6. Create SOAP Envelope strSoapEnvelope like this:
    strSoapEnvelope = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
    strSoapEnvelope += "<soap:Envelope ";
    strSoapEnvelope += "xmlns:xsi = \"http://www.w3.org/2001/XMLSchema-instance\" ";
    strSoapEnvelope += "xmlns:xsd= \"http://www.w3.org/2001/XMLSchema\" ";
    strSoapEnvelope += "xmlns:soap= \"http://schemas.xmlsoap.org/soap/envelope/\">";
    strSoapEnvelope += "<soap:Body>";
    strSoapEnvelope += "<AddTwoNumbers  
    	xmlns=\"http://localhost/wwwroot/addnumbers/Service1\">";
    strSoapEnvelope +="<a>10</a>";
    strSoapEnvelope += "<b>12</b>"
    strSoapEnvelope += "</AddTwoNumbers >";
    strSoapEnvelope += "</soap:Body>";
    strSoapEnvelope += "</soap:Envelope>";
  7. Create an instance of ServerXMLHTTP40.
    objXMLHttp = new ServerXMLHTTP40();
  8. Set the header of SOAP request.
    objXMLHttp.open("POST", http://192.168.84.90/AddNumbers/Service1.asmx,false,"","")
    objXMLHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    objXMLHttp.setRequestHeader("SOAPAction", 
    	"http://localhost/wwwroot/addnumbers/Service1/AddTwoNumbers");
  9. Send the SOAP request.
    objXMLHttp.send(strSoapEnvelope.ToString());
  10. Wait for some time.
    objXMLHttp.waitForResponse(500);
  11. Take response in string outXML.
    string outXML = objXMLHttp.responseText.ToString();
  12. Display result in label(ID= label1):
    Label1.Text = outXML.ToString();

License

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

About the Author

Vimal Kamothi

Web Developer

India India

Member



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
GeneralWorks great! Pinmemberjasonee4:59 15 Mar '11  
GeneralMy vote of 5 PinmemberKo Ko Min Min Thein21:59 26 Jul '10  
GeneralMy vote of 1 Pinmemberbinarycheese9:26 27 Apr '09  
GeneralMy vote of 1 PinmemberFuzzychaos3:48 23 Mar '09  
GeneralMy vote of 1 Pinmembervirusstorm4:41 3 Mar '09  
GeneralMy vote of 1 PinmemberDave Sexton4:42 20 Feb '09  
Questionerror Pinmemberaminbeheshti19:10 4 Feb '09  
GeneralSystem.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction. PinmemberAnujit18:18 17 Nov '08  
GeneralSOAP request to a webservice Pinmemberwebmavin1:41 1 May '07  
GeneralRe: SOAP request to a webservice PinmemberRedDiamonds21:57 22 Jan '09  
GeneralGreat Article PinmemberSatisht715:59 5 Mar '07  
QuestionSystem.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction. Pinmembersunil047492:08 19 Dec '06  
GeneralNice work... but.... PinmemberpinoyBug23:17 25 Feb '05  
GeneralRe: Nice work... but.... PinmemberChintak Chhapia16:41 28 Feb '05  

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
Web01 | 2.5.120517.1 | Last Updated 27 Feb 2005
Article Copyright 2005 by Vimal Kamothi
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid