MessageContract serialization with DCS

Posted by kurtaj on Stack Overflow See other posts from Stack Overflow or by kurtaj
Published on 2010-05-05T16:42:34Z Indexed on 2010/05/05 17:18 UTC
Read the original article Hit count: 235

Is there a way to make the DataContractSerializer serialize a [MessageContract] the same way it appears when transmitted over SOAP?

I have a class that appears as follows on the wire for a WCF call:

<TestRequest xmlns="http://webservices.test.com/ServiceTest/1.1">
  <Name>Just Me</Name>
</TestRequest>

When serializing using the DCS, it looks like this:

<TestRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance" z:Id="1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://schemas.datacontract.org/2004/07/ServiceTest">
  <_x003C_Name_x003E_k__BackingField z:Id="2">Just Me</_x003C_Name_x003E_k__BackingField>
</TestRequest>

I'm convinced this inconsistency is because my class is marked up as a message contract instead of a data contract:

    [MessageContract]
    [Serializable]
    public class TestRequest
    {
        [MessageBodyMember]
        public string Name { get; set; }
    }

Is there a way to make the DCS serialize messages the same way WCF does when it creates a SOAP message?

© Stack Overflow or respective owner

Related posts about c#

Related posts about datacontractserializer