Question

I have a WCF service in which I have some data contracts. I'm using web service software factory, which uses a designer to create all the message and data and other contracts, and it creates them as partial classes. When the code is regenerated the classes are recreated.

using WcfSerialization = global::System.Runtime.Serialization;

[WcfSerialization::CollectionDataContract(Namespace = "urn:CAEService.DataContracts", ItemName = "SecurityItemCollection")]
public partial class SecurityItemCollection : System.Collections.Generic.List<SecurityItem>
{
}

The data contract is a generic List of a custom class which was working fine. However I now want to add a property to this class, so I added this partial class in the same namespace:

public partial class SecurityItemCollection
{
    public int TotalRecords { get; set; }
}

This seems to work fine on the service side, but when I compile and then update the service reference from the client, the class doesn't have the new property i.e. when it serialises it and recreates it on the client side, it's missing the new property. Anyone know why this is?

TIA

EDIT: Ok this is officially driving me nuts. The only thing I can see is that it is using the CollectionDataContract attribute instead of DataContract. Does this somehow not allow data members in the class to be serialised? Why would that be? It is working fine on the service side - I can see and populate the values no problem. However when I update the service refernce on my client there's nothing, just the colelction class without the data member.

Was it helpful?

Solution 2

Ok after much searching I finally found out that this isn't allowed i.e. classes marked as CollectionDataContract can't have data members. Why this is I have no idea but it cost me several hours and a major headache. See link below:

WCF CollectionDataContract and DataMember

OTHER TIPS

Try to add the DataMember attribute to the TotalRecords property

I know this is old but it kept coming up when I searched on this subject. I was able to get this working by adding a "DataMemberAttribute" attribute to the property. Below is a code example.

public partial class SecurityItemCollection
{
    [global::System.Runtime.Serialization.DataMemberAttribute()]
    public int TotalRecords { get; set; }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top