Sunday, January 21, 2007

Optimizing SOAP message serialization/deserialization

Today I got a positive feedback from Dr. Sanjiva Weerwarana on my MSc project proposal. According to him it's an interseting idea, but a challanging work. I consider my self really lucky if I get the oppertunity to work with him. I'll be meeting him on next Friday to discuss more on the project proposal.

This is what I am exactly planning to do. Those who are new to this post please also go through the previous one - quite relavent to this : SOAP message serialization.

Before moving forward we need to understand the anatomy of a web service, first. Then I'll explain where my proposal fits in. I found the following diagram in the MSDN web site which is quite useful.



The following describes the sequence of events that occur when an XML Web service is called:

1. The client creates a new instance of an XML Web service proxy class. This object resides on the same computer as the client.

2. The client invokes a method on the proxy class.

3. The infrastructure on the client computer serializes the arguments of the XML Web service method into a SOAP message and sends it over the network to the XML Web service.

4. The infrastructure receives the SOAP message and deserializes the XML. It creates an instance of the class implementing the XML Web service and invokes the XML Web service method, passing in the deserialized XML as arguments.

5. The XML Web service method executes its code, eventually setting the return value and any out parameters.

6. The infrastructure on the Web server serializes the return value and out parameters into a SOAP message and sends it over the network back to the client.

7. The XML Web service infrastructure, on the client computer, receives the SOAP message, deserializes the XML into the return value and any out parameters, and passes them to the instance of the proxy class.

8. The client receives the return value and any out parameters.

As you carefully go through the above steps you'll notice that there is a huge bottleneck in SOAP message serialization/deserialization process. Also add the number of times this happens in a single web service operation. This is what, which seperates web services from platform dependant destributed technologies such as RMI and Remoting. So my proposal simply talks about one such technique to reduce the overhead in this SOAP message serialization process.

The area I am touching is already being researched by many people in the past. Some of those techniques were discussed in my previous post. My first objective is to identify where exactly the previous researches stopped and analyse the techniques they utilized. Then to come up with a working implementation to solve the issue. Being more towards the .Net side - I'll be focusing on SOAPExtensions during the implementation.

Following explains how SOAP Extensions are used in the SOAP message serialization/deserialization process.

Client Side Prepares a Request Message

1. A client invokes a method on the proxy class.
2. A new instance of the SOAP extension is created on the client.
3. If this is the first time this SOAP extension has executed with this Web service on the client, then the GetInitializer method is invoked on the SOAP extension running on the client.
4. The Initialize method is invoked.
5. The ChainStream method is invoked.
6. The ProcessMessage method is invoked with SoapMessageStage set to BeforeSerialize.
[This is a place which can be used for client side caching]
7. ASP.NET on the client computer serializes the arguments of the Web service method into XML.
8. The ProcessMessage method is invoked with SoapMessageStage set to AfterSerialize.
9. ASP.NET on the client computer sends the SOAP message over the network to the Web server hosting the Web service.

Server Side Receives a Request Message and Prepares a Response

1. ASP.NET on the Web server receives the SOAP message.
2. A new instance of the SOAP extension is created on the Web server.
3. On the Web server, if this is the first time this SOAP extension has executed with this Web service on the server side, the GetInitializer method is invoked on the SOAP extension running on the server.
4. The Initialize method is invoked.
5. The ChainStream method is invoked.
6. The ProcessMessage method is invoked with SoapMessageStage set to BeforeDeserialize.
7. ASP.NET deserializes the arguments within the XML.
8. The ProcessMessage method is invoked with SoapMessageStage set to AfterDeserialize.
9. ASP.NET creates a new instance of the class implementing the Web service and invokes the Web service method, passing in the deserialized arguments. This object resides on the same computer as the Web server.
10.The Web service method executes its code, eventually setting the return value and any out parameters.
11.The ProcessMessage method is invoked with SoapMessageStage set to BeforeSerialize.
12.ASP.NET on the Web server serializes the return value and out parameters into XML.
13.The ProcessMessage method is invoked with SoapMessageStage set to AfterSerialize.
14.ASP.NET sends the SOAP response message over the network back to the Web service client.

Client Side Receives a Response Message

1. ASP.NET on the client computer receives the SOAP message.
2. The ProcessMessage method is invoked with SoapMessageStage set to BeforeDeserialize.
3. ASP.NET deserializes the XML into the return value and any out parameters.
4. The ProcessMessage method is invoked with SoapMessageStage set to AfterDeserialize.
5. ASP.NET passes the return value and any out parameters to the instance of the proxy class.
6. The client receives the return value and any out parameters.

Keep tuning in - more will be posted as I progress...

1 comment:

  1. Interesting Topic.
    keep posting your progress.
    Thanks
    Ranga

    ReplyDelete