none
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)

      <s:Body>
        <BalanceInquiry xmlns="--some namespace--">
          <request xmlns:a="http://schemas.datacontract.org/2004/07/App.Data" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:Account>
              <a:AccountNumber>1029292929</a:AccountNumber>
              <a:Track1>--Track1--</a:Track1>
              <a:Track2>--Track2--</a:Track2>
            </a:Account>
          </request>
        </BalanceInquiry>
      </s:Body>

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

    <RequestMessage xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.datacontract.org/2004/07/App.Data\"><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,

    Edward


    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 MSDNFSF@microsoft.com.

    Thursday, February 2, 2017 4:34 AM