次の方法で共有


WCF: WCF (xmlSerialization) dropping certain properties of an object during serialization

Task:

To consume the JavaService from a WCF client application.

 

Issue:

WCF Client using XML Serialization dropping certain properties, even though we set them correctly.

 

Tools used to confirm this:

Fiddler traces

 

From WSDL

When we add the service reference via (WSDL file) exposed from Java service we see proxy class methods decorated with XMLSerialization attribute.

Further we also identified that WSDL has set minOccurs attrbute to 0. When this happens, for every non-string property, there is a corresponding generated property called PropertyNameSpecificed. So if I have a property name Amount and it is a decimal type, I will have a generated property called AmountSpecified. 

<xs:element minOccurs="0" name="validFrom" type="xs:dateTime"/>

 

When a field/property say myProperty is marked as optional in a SOAP message WCF creates an corresponding extra MyPropertySpecified property that must be set to true when the MyPropertySpecified value is set. Otherwise WCF will not serialize nor send that property

  • In the generated Reference.cs file each optional will have a corresponding IsSpecified property, 

  • like so:  

  • private System.DateTime validFromField;

  • private bool validFromFieldSpecified;

 

Solution:

To allow WCF client to perform the correct serialization, we need to set the "IsSpecified" attribute to TRUE on all these properties.

 

I hope this helps !