General Question on Message Contract

May 19, 2009 at 5:53 PM


I know that wcf does the serialization and dezerialization of request object before it comes to the service. Is there a way to get the xml format of the request message object in public functions of service.

Basically i have different name value collection pairs in the request object. I need to apply xslt to this xml to get the required output xml.

So the basic point is to get the xml message of request apply xslt and proceed further in the implementation part.


Any ideas?



May 20, 2009 at 11:06 AM
Edited May 20, 2009 at 11:13 AM

You may get teh xml message content with someting like this:

public class CustomerService : IUniversalOneWay
    #region IUniversalOneWay Members
    public void ProcessMessage(Message msg)
        Console.WriteLine("Message received...");
        XmlDocument doc = new XmlDocument();
        Console.WriteLine("Customer: {0} ({1})",

If your operation parameter is not of Message type, you can get the current message object from "OperationContext.Current.RequestContext.RequestMessage"

You can also find further info on WCF Serialization here:

Or some msg extensibility here:



May 21, 2009 at 12:58 PM

Thanks for the info Hernan.

I saw the links sent by you. So i think i need to serialize the request object back after wcf has deserialized based on my requirement. correct me if i am wrong.

Also, can i know whether there is any performance impact if i serialize the object into xml apply an xslt and get the transformed xml. Otherwise i can look into getting the data from SQL data base or Sharepoint list instead of applying xslt.



May 21, 2009 at 5:09 PM

When using XML serialization (even XmlDoc) you may get a perf hit (with transform as well). The best way to be sure about the scope of the perf impact is to actually test with and without serialization or profiling the different parts of your serialization process.

On the other hand, using DB may also introduce some latency/perf degradation but that me be mitigated by connection and data caching (something similar may be applied to serialization).

So at the end, the best way to deal with perf decisions will be to perform the required tests and evaluate accordingly.