WCF does not serialize all properties

I am using a SOAP service that was imported as a service reference in VS2010. I call one of the services with the request object provided by the service. The problem I am facing is that not all properties of the object are serialized or, rather, are not sent over the wire. The request object is as follows:

var serviceRequest = new UpdateRequest{ StoreId = request.StoreId, Id = request.Id, Status = (Status)Enum.Parse(typeof(Status), request.myStatus.ToString()), parameters = request.Parameters, validFrom = request.ValidFrom.Value, validFromSpecified = request.ValidFromSpecified }; 

And that’s what was sent over the wire. I captured it using wirehark

 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <updateStore xmlns="http://localhost.service.com/"> <StoreRequest> <StoreId>1234</StoreId> <validFrom>2011-11-29T00:00:00</validFrom> <parameters> <param1>true</param1> </parameters> </StoreRequest> </updateStore> </s:Body> </s:Envelope> 

Two parameters, Id and Status, were not sent to the service, and I just cannot understand why. The values ​​are set and the generated WSDL properties are publicly available and have the same serialization attributes as the serializable properties.

Any help would be appreciated.

Edit ---- Updated with generated service code

 /// <remarks/> [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://myservice.com/")] public partial class StoreUpdateRequest : object, System.ComponentModel.INotifyPropertyChanged { private long StoreIdField; private long IdField; private bool IdFieldSpecified; private Status StatusField; private bool StatusFieldSpecified; private long storeIdField; private bool storeIdFieldSpecified; private System.DateTime validFromField; private bool validFromFieldSpecified; private System.DateTime validToField; private bool validToFieldSpecified; private technicalParameters parametersField; /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(Order=0)] public long StoreId { get { return this.StoreIdField; } set { this.StoreIdField = value; this.RaisePropertyChanged("StoreId"); } } /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(Order=1)] public long Id { get { return this.IdField; } set { this.IdField = value; this.RaisePropertyChanged("Id"); } } 
+7
source share
1 answer

The problem is resolved. The error was that the SOAP service was updated and some properties are now optional. When a field / property says XX is marked optional in the SOAP message, WCF creates the corresponding optional XXIsSpecified property, which should be set to true when XX is set . Otherwise, WCF will not serialize or send this property.

There are various ways to determine if a property is set as optional.

  • In the generated Reference.cs file, each additional parameter will have a corresponding IsSpecified property, for example: private System.DateTime validFromField; private bool validFromFieldSpecified; private System.DateTime validFromField; private bool validFromFieldSpecified;

  • You can use soapUI to view and test wsdl

  • Go to wsdl with chrome or another browser and see if the element has the minoccurs attribute. If it is and it has a value of 0, then it is optional. for example, <xs:element minOccurs="0" name="validFrom" type="xs:dateTime"/>
+22
source

All Articles