WCF doesn't serialize all properties

前端 未结 1 764
暗喜
暗喜 2021-02-09 07:45

I\'m consuming a SOAP service that has been imported as a Service Reference in VS2010. I call one of the services with a request object that is provided by the service. The prob

相关标签:
1条回答
  • 2021-02-09 07:51

    The problem is resolved. The error was that the SOAP service had been updated and some properties now where optional. When a field/property say XX is marked as optional in a SOAP message WCF creates an corresponding extra XXIsSpecified property that must be set to true when the XX value is set. Otherwise WCF will not serialize nor send that property.

    There are different ways to see if a property is set as optional.

    • In the generated Reference.cs file each optional will have a corresponding IsSpecified property, like so: private System.DateTime validFromField; private bool validFromFieldSpecified;

    • You can use soapUI to see and test the wsdl

    • Browse to the wsdl with chrome or another browser and see if the element has the minoccurs attribute. If it's there and it has the value of 0 then it's optional. like this <xs:element minOccurs="0" name="validFrom" type="xs:dateTime"/>
    0 讨论(0)
提交回复
热议问题