SOAP Communication Model.

SOAP Communication Model.

All communication by SOAP is done via the HTTP protocol. Prior to SOAP, a lot of web services used the standard RPC (Remote Procedure Call) style for communication. This was the simplest type of communication, but it had a lot of 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 which provided 2 methods as

  • GetEmployee – This would get all Employee details
  • SetEmployee – This would set the value of the details like employees dept, salary, etc. accordingly.

In the normal RPC style communication, the client would just call the methods in its request and send the required parameters to the server, and the server would then send the desired response.

The above communication model has the below serious limitations

  1. Not Language Independent – The server hosting the methods would be in a particular programming language and normally the calls to the server would be in that programming language only.
  2. Not the standard protocol – When a call is made to the remote procedure, the call is not carried out 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 – Since RPC calls do not go via the normal protocol, separate ports need to be open on the server to allow the client to communicate with the server. Normally all firewalls would block this sort of traffic, and a lot of configuration was generally required to ensure that this sort of communication between the client and the server would work.

To overcome all of the limitations cited above, SOAP would then use the below communication model.

  1. The client would format the information regarding the procedure call and any arguments into a SOAP message and sends it to the server as part of an HTTP request. This process of encapsulating the data into a SOAP message was known as Marshalling.
  2. The server would then unwrap the message sent by the client, see what the client requested for and then send the appropriate response back to the client as a SOAP message. The practice of unwrapping a request sent by the client is known as Demarshalling.

Practical SOAP Example

Let see a practical example,

Probably one of the best ways to see how SOAP messages get generated is to actually see a web service in action.

This topic will look at using the Microsoft.Net framework to build an ASMX web service. This type of web service supports both SOAP version 1.1 and version 1.2.

ASMX web services automatically generate the Web Service Definition Language (WSDL) document. This WSDL document is required by the calling client application so that the application knows what the web service is capable of doing.

In our example, we are going to create a simple web service, which will be used to return a string to the application which calls the web service.

This web service will be hosted in an Asp.Net web application. We will then invoke the web service and see the result that is returned by the web service.

Visual Studio will also show us what the SOAP message being passed between the web service and the calling application.

The first pre-requisite to setup our Web service application which can be done by following the below steps.

Step 1) The first step is to create an empty ASP.Net Web application. From Visual Studio, click on the menu option File->New project.

Once you click on the New Project option, Visual Studio will then give you another dialog box for choosing the type of project and to give the necessary details of the project. This is explained in the next step.

Step 2) In this step,

  1. Ensure to first choose the C# web template of ASP.NET Web application. The project has to be of this type in order to create web services project. By choosing this option, Visual Studio will then carry out the necessary steps to add required files which are required by any web-based application.
  2. Give a name for your project which in our case has been given as webservice.asmx. Then ensure to give a location where the project files will be stored.

Step 3) In this step,

We are going to add a Web service file to our project

  1. First Right-click on the project file
  2. Once you right-click on the project file, you have the chance to choose the option “Add->Web Service(ASMX) to add a web service file. Just provide a name of Tutorial Service for the web service name file.
  3. screen open with default code

Code Explanation:

  1. This line of code provides a name for your web service file. This is an important step because it gives way for the client application to call the web service via the name of the web service.
  2. Normally a class file is used to encapsulate the functionality of a web service. So the class file will have the definition of all the web methods which will provide some functionality to the client application.
  3. Here [WebMethod] is known as an attribute which describes a function. The subsequent step creates a function called “helloworld”, but with the inclusion of this step of adding a [WebMethod] attribute makes sure that this method can be invoked by a client application. If this attribute is not in place, then the method can never be called by a client application.
  4. Here we are defining a function called ‘helloworld’ which will be used to return a string to the calling client application. This function is a web service which can be called by any client application.
  5. We are using the return statement to return the string “This is a helloworld” to the client application.

All steps images Attached and I want to thanks guru99 also for wonderful guidance .

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *