Web Services (ASMX 1.1) Performance Guidelines - Serialization

From Guidance Share

Jump to: navigation, search

- J.D. Meier, Srinath Vasireddy, Ashish Babbar, and Alex Mackman


Reduce Serialization with XmlIgnore

To limit which fields of an object are serialized when you pass the object to or from a Web method and to reduce the amount of data sent over the wire, use the XmlIgnore attribute as shown in the following code snippet. The XmlSerializer class ignores any field annotated with this attribute.

Note Unlike the formatters derived from the IFormatter interface, XmlSerializer serializes only public members.

  // This is the class that will be serialized. 
  public class MyClass
  {
     // The str1 value will be serialized.
     public string str1;
     /* This field will be ignored when serialized--
        unless it's overridden. */
     [XmlIgnoreAttribute]
     public string str2;
  } 


Reduce Round Trips

Reducing round trips to a Web service reduces the number of times that messages need to cross serialization boundaries. This helps reduce the overall serialization cost incurred. Design options that help to reduce round trips include the following:

  • Use message-based interaction with a message-based programming model, rather than an RPC style that requires multiple object interactions to complete a single logical unit of work.

In some cases, split a large payload into multiple calls to the Web service. Consider making the calls in parallel using asynchronous invocation instead of in series. This does not technically reduce the total number of round trips, but in essence the client waits for only a single round trip.


Consider XML Compression

Compressing the XML payload sent over the wire helps reduce the network traffic significantly. You can implement XML compression by using one of the following techniques:

  • Use SOAP extensions on the server and client for the compression and decompression of requests and responses.
  • Use a custom HTTP module on the server and override the proxy for the Web service on the client.
  • Use HTTP compression features available in IIS 5.0 and later versions for compressing the response from the Web services. Note that you need a decompression mechanism on the client.


References

For more information about serialization, see:

Personal tools