Master java skills

SOAP Communication Model

Communication in SOAP happens over HTTP protocol. Before SOAP, many web services used standard RPC (Remote Procedure Call) style for communication. It was the simplest type of communication, but it had many limitations.

Let’s consider the below diagram to see how this communication works. In this example, let’s assume the server hosts a web service. This service has two methods

  1. GetPlayer – Gets the player details
  2. SetPlayer – Sets the player details

RPC type communication

In the normal RPC style communication, the client would just make a call to the methods. It will send the required parameters to the server. Then the server would send the desired response. But such communication style has following limitations

  1. Language Dependent – The calls to the methods hosting on the server would be in the same language in which the server code has been written.
  2. Non-standard protocol – When a call is made to the remote procedure, the call is not made via the standard protocol. This was an issue since mostly all communication over the web had to be done via the HTTP protocol.
  3. Firewalls – For RPC calls separate ports require to be opened on the server to allow the communication with the client. Normally, all firewalls would block this kind of calls. Therefore, a lot of configuration was required to be done to allow such RPC calls.

All these limitations have been overcome in SOAP based protocol.

SOAP Based Communication
  1. In this approach, the client would format the information regarding the method call and required request parameters into a SOAP message. Then it will send it to the server as part of an HTTP request. This process of encapsulating the data into a SOAP message is called Marshalling.
  2. The server would then unwrap the message sent by the client. It will process the request and send back the response in the SOAP format. The unwrapping of SOAP data is called Demarshalling.

Let’s Understand it with an example

Let’s assume there is a core banking application which exposes soap webservice operations.

One of its operations is to give back the account balance against an account number.

Now, there is a mobile banking client application which needs to consume this soap webservice operation. The client sends the account number as part of the SOAP request. Below is a sample request

<?xml version="1.0"?>

<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">

<soap:Body xmlns:p="http://www.example.org/abcbank">
  <p:GetAccountBalanceRequest>
    <p:AccountNumber>1230987654</p:AccountNumber>
  </p:GetAccountBalanceRequest>
</soap:Body>

</soap:Envelope>

Below is the response

<?xml version="1.0"?>

<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">

<soap:Body xmlns:p="http://www.example.org/abcbank">
  <p:GetAccountBalanceResponse>
    <p:AccountBalance>250000</p:AccountBalance>
  </p:GetAccountBalanceResponse>
</soap:Body>

</soap:Envelope>

Step by step explanation

  1. The client formats information regarding the procedure call and any arguments into a SOAP message and sends it to the server as part of an HTTP request.
  2. The web server translates the incoming SOAP message into a local method invocation. The local method does the processing and gets the balance against the account number.
  3. The server marshals the result of the local method call into a SOAP message.
  4. The server transmits the SOAP response to the client in the form of a HTTP response.