Wednesday, April 4, 2012

SOAP message properties are ignored in WCF

Last week, we discovered a strange bug inside WCF.
We have the following datacontract which represents a surface size expressed in Ha, A and Ca:
[DataContract(Namespace = Constants.SCHEMANAME + "Perceel")]
   public class SurfaceSize
   {
       [DataMember(IsRequired = false)]
       public int? Ha { get; set; }
       [DataMember(IsRequired = false)]
       public int? A { get; set; }
       [DataMember(IsRequired = false)]
       public decimal? Ca { get; set; }
   }

We noticed that only the Ha value was saved into the database. We looked at the NHibernate mapping files, the domain mapping code, the queries,… everything looked okay. So we took a look at the only place that was left, the message communication itself.

The following message data was send to us:
<c:SurfaceSize>
 <c:Ha>99</e6:Ha>
 <c:A>9</e6:A>
 <c:Ca>10</e6:Ca>
</c:SurfaceSize>


We discovered that changing the order of the parameters inside the message solved the problem:

<c:SurfaceSize>
   <c:A>9</c:A>
   <c:Ca>10</c:Ca>
   <c:Ha>99</c:Ha>
</c:SurfaceSize>


No idea why WCF ignores the parameters when the order has changed. We are not using the Order attribute on our DataContracts.

Anyone who has a clue?

2 comments:

Anonymous said...

Maybe this link is helpful
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a891928b-d27a-4ef2-83b3-ee407c6b9187

Bart Wullems said...

Thanks for the link! It gives some extra inside into the problem(unfortunately no solution :-()