DataContractSerializer output does not match SOAP body XML for same data contract RRS feed

  • Question

  • Folks:

    I have a situation where I have a WCF service using BasicHttpBinding, and when I call a method with a given contract, the contarct looks like this over the wire: (just showing the SOAP body here for brevity)

        <BalanceInquiry xmlns="--some namespace--">
          <request xmlns:a="" xmlns:i="">

    But when I serialize the exact same contract with DataContractSerializer in code (e.g. in a console application), I get this:

    <RequestMessage xmlns:i=\"\" xmlns=\"\"><Account><AccountNumber>1029292929</AccountNumber><Track1>--Track1--</Track1><Track2>--Track2--</Track2></Account></RequestMessage>

    The contract class is the same in both cases, and the type name of the DataContract class is RequestMessage, NOT "BalanceInquiry", which is the name of the operation contract method.

    Does anyone know about this? I need to be able to duplicate serialization in code for a very specific reason.

    • Edited by RodKestler Tuesday, January 31, 2017 9:25 PM
    Tuesday, January 31, 2017 9:21 PM

All replies

  • Hi RodKestler,

    The structure of SOAP body is Body->Operation Contract method->Data Contract class. DataContractSerializer serializes and deserializes an instance of a type into an XML stream or document using a supplied data contract which will only contains data contract class.

    Do you mean you want to change the serialization of WCF Soap body? If so, what is your expected result? If you want to remove the Operation Contract method from SOAP, I think it is impossible, otherwise, your service would not work for missing operation method.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, February 2, 2017 4:34 AM