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
- Start a new ASP.NET web application.
- 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.
- Create one label to display result (
ID = lablel1
).
- Declare
objXMLHttp
of type MSXML2.ServerXMLHTTP40
.
Protected MSXML2.ServerXMLHTTP40 objXMLHttp
- Declare one
string strSoapEnvelope
which contains soap request.
string strSoapEnvelope= “”;
- 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>";
- Create an instance of
ServerXMLHTTP40
.
objXMLHttp = new ServerXMLHTTP40();
- Set the header of SOAP request.
objXMLHttp.open("POST", http:objXMLHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
objXMLHttp.setRequestHeader("SOAPAction",
"http://localhost/wwwroot/addnumbers/Service1/AddTwoNumbers");
- Send the SOAP request.
objXMLHttp.send(strSoapEnvelope.ToString());
- Wait for some time.
objXMLHttp.waitForResponse(500);
- Take response in string outXML.
string outXML = objXMLHttp.responseText.ToString();
- Display result in
label(ID= label1):
Label1.Text = outXML.ToString();