C # WCF data contract partial class - new field in second partial class not matched

I have a WCF service in which I have some data contracts. I use factory web services software which uses a constructor to create all messages and data and other contracts and 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>
{
}

A data contract is a generic list of a user class that works fine. However, now I want to add a property to this class, so I added this partial class to the same namespace:

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

, , , , , . - , ?

EDIT: , . , , , DataContract CollectionDataContract. - ? ? - . , refernce , , colelction .

+3
3

, , , CollectionDataContract, . , . . :

WCF CollectionDataContract DataMember

+3

DataMember TotalRecords

+3

I know this is out of date, but it continued when I searched for this topic. I was able to get this working by adding the "DataMemberAttribute" attribute to the property. The following is sample code.

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

}
+2
source

Source: https://habr.com/ru/post/1779156/


All Articles