Remote Procedure Calls using SOAP

Posted by Ranjith Articles | Web Services in C# October 04, 2002
Here is the sample RPC (remote procedure call) using SOAP ( simple object access protocol).
Reader Level:

Here is the sample RPC (remote procedure call) using SOAP ( simple object access protocol). A SOAP message is an XML format sent over HTTP to a remote server where the Web service is located.

The Web service processes the soap request and returns the value to the client using soap response.

POST/ FirstSoap.aspx HTTP/1.1
Content-Type: text/xml; charset="utf-8"
SOAPAction: "uri:uniqueuriofthewebservice"
<!-- namespace for envelope -->
xmlns:SOAP-ENV = "">
<!-- namespace for xml schema specification ( for data type declarations) -->
xmlns:xsi = "">
user email id
SOAP-ENV:Body xmlns:BODYNS="URI1">
parm1 xsi:type="int">1</parm1>
parm2 xsi:type="string">Ranjith</parm2>
parm3 xsi:type="string">Rajadurai</parm3>
faultstring>application error</faultstring>
faulterror>server name</faultactor>
detail xmlns:Faultns="URI2">
Faultns:Message>Wrong number of parameters</Faultns:Message>
return>My First RPC responded successfully</return>

This soap message contains three basic elements

  1. Envelope
  2. Header (optional)
  3. Body

All the soap message should be within the envelope element.

Each element should have namespace for scoping. Member of the element can be accessed within that namespace.Namespace is required to avoid confusion incase of having same element names in different places within a message.

In this soap message header element passes the user email id for authentication.

"mustUnderstand" attribute in the header element will make this as mandatory i.e the web service that is going to process this soap message must understand the parameter passed in that header element.

The flag is set to "1" to make this authentication as mandatory. Now the soap message is authenticated before processing. Otherwise, it will not process the soap message.

Body element has a method which is specified in the WSDL of the web service.

This method can be defined in any language in the web service.This method contains three parameters.

There datatype also defined using the namespace "xsi". If this soap message is correctly defined it will invoke the FirstMethod web service and return a value.

If there is any error during processing the message, a fault message is returned that is defined in Fault tag within the body. This is message is shown only incase of error during processing. If there is any error during transfering the data or parameters to the web services normal HTTP error is shown.Any fault messages can have four sub elements.

  1. faultcode(optional) - contains the type of error occured.
  2. faultstring(optional) - contains the cause of the error.
  3. faultactor - specifies the server name where the error is occurred.
  4. details - contains two sub elements.
    a. message - contains the detail error messge
    b. errorcode - contains the error code.

After successful exceution of the Firstmethod web service it will return a string
which is wrapped by XML tags. FirstMethodResponse element is responsible for returning the value.

Any response element will be in the form of method name suffix "Response".

This soap message is sent in the form of HTTP packets to the url Web service invoked is "FirstMethod" service.
Soap action specifies the unique URI of the web service invoked.