Serializing MessageContract with DCS
Is there a way to make the DataContractSerializer serialize the [MessageContract]
same way it appears when transmitted over SOAP?
I have a class that looks like the following on a wire for a WCF call:
<TestRequest xmlns="http://webservices.test.com/ServiceTest/1.1">
<Name>Just Me</Name>
</TestRequest>
When serialized using 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 am convinced that this inconsistency is that my class is marked as a contract with a message, not a data contract:
[MessageContract]
[Serializable]
public class TestRequest
{
[MessageBodyMember]
public string Name { get; set; }
}
Is there a way to make DCS messages serialize the same way when WCF creates a SOAP message?
a source to share
I think you are looking for Data Contract Surrogates . BTW you can use DataContractSerializer constructor to set namespace and root name.
a source to share