Short solution for short problems

Serialized SOAP has some records empty and set to reference another.

Since I have a .Net back end WCF service and a front end iOS consumer, I have tackled several new challenges and learned a lot of what SOAP is all about. The next strange thing I encountered and it took me an hour or 2 to find out the solution was:

On my iOS client I suddenly got 15 records, where 7 of then were just empty records. I could not find the reason, on the server SQL all records were there and all records were filled in and unique. Then I took a closer look to the incoming SOAP message and found out that there were 7 records that looked like this:

<a:GP_MES_SetOrderPosReadyHistory xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Ref="i1"/>

So no contents only an empty xml tag with at the end z:Ref="i1". Soon I discovered that it was referencing a record that was found earlier in the XML with the same keys. So strange, because the rest of the item was different. At this website I found out that settings the IsReference property on the data contract creates this behavior. So one thing you could do is to set it to false. In my case the data contracts were generated by self tracking entities. So I discovered that I had to adjust the key fields of the entities. In my case it was on a view and the key fields were not unique for each records. So I added an extra field to the key fields and now it works perfect.