views:

90

answers:

1

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"&gt;
  <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"&gt;
  <_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?

A: 

I guess you are looking for Data Contract Surrogates. BTW you can use the DataContractSerializer's constructor to set the namespace and root name.

danish
Data Contract Surrogates are not what I want. I want to create the SOAP XML exactly the same way WCF does.
kurtaj