SOAP is an XML-based messaging protocol.It defines a set of rules for structuring messages that can be used for simple one-way messaging but is particularly useful for performing RPC-style (Remote Procedure Call) request-response dialogues. It is not tied to any particular transport protocol though HTTP is popular. Nor is it tied to any particular operating system or programming language so theoretically the clients and servers in these dialogues can be running on any platform and written in any language as long as they can formulate and understand SOAP messages. As such it is an important building block for developing distributed applications that exploit functionality published as services over an intranet or the internet.
The SOAP message syntax is described in detail at http://www.w3.org/TR/SOAP/.
A valid SOAP Message is a well-formed XML document. It should use the SOAP Envelope and SOAP Encoding namespaces and have the following
Sample SOAP Request XML of my own
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header /> <SOAP-ENV:Body> <CategoryRQ xmlns="urn:Test_Request"> <REQUESTSOURCE> <CategoryList categoryname="abc" count="5" /> </REQUESTSOURCE> </CategoryRQ> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Creating SOAP Client is simple in .Net with the help of SOAP Toolkit.
The toolkit provides basic Web services capabilities for COM components and applications.
Implementation of above sample XML SOAP Envelope using Soap Toolkit with .NET C# is shown below.
MSSOAPLib.HttpConnector Connector = new MSSOAPLib.HttpConnector();
Connector.set_Property("EndPointURL", "http://www.webtips.co.in/soap/TestWebservice/message");
Connector.Connect();
Connector.BeginMessage();
MSSOAPLib.SoapSerializer Serializer = new MSSOAPLib.SoapSerializer();
Serializer.Init(Connector.InputStream);
Serializer.startEnvelope("", "", "");
Serializer.SoapAttribute("xmlns:xsd", "", "http://www.w3.org/1999/XMLSchema", "");
Serializer.SoapAttribute("xmlns:SOAP-ENV", "",
"http://schemas.xmlsoap.org/soap/envelope/", "");
Serializer.startHeader("");
Serializer.endHeader();
Serializer.startBody("");
Serializer.startElement("CategoryRQ", "urn:Test_Request",
"http://schemas.xmlsoap.org/soap/encoding/", "");
Serializer.startElement("REQUESTSOURCE", "", "", "");
Serializer.startElement("CategoryList", "", "", "");
Serializer.SoapAttribute("categoryname", "", "abc", "");
Serializer.SoapAttribute("count", "", "5", "");
Serializer.endElement();
Serializer.endElement();
Serializer.endElement();
Serializer.endBody();
Serializer.endEnvelope();
Connector.EndMessage();
MSSOAPLib.SoapReader Reader = new MSSOAPLib.SoapReader();
Reader.Load(Connector.OutputStream, "");
Response.Write(Reader.DOM.xml);
SOAP Client code makes a service call by invoking the appropriate method in the SOAP package. The SOAP package's SOAP serializer converts this invocation into a SOAP request and sends that to the HTTP encoder. The HTTP encoder wraps the SOAP message in a HTTP request and sends it to the SOAP server. The response is received from the SOAP server by the HTTP encoder/decoder module which decodes it and extracts the SOAP response which it hands to the SOAP deserializer. The SOAP deserializer deserializes the message and passes the result to the client code as the return value to the orginal invocation.