I have data contract for WCF and its got custom class variable reference, I wondering do I need to do anything additional in configuration or anything else. i.e. AddressData
[DataContract]
public class MemberData : IIdentifiableEntity
{
[DataMember]
public int MemberID { get; set; }
[DataMember]
public string Title { get; set; }
[DataMember]
public string Surname { get; set; }
[DataMember]
public string Forename { get; set; }
[DataMember]
public string MiddleName { get; set; }
[DataMember]
public string PrevSurname { get; set; }
[DataMember]
public System.DateTime DOB { get; set; }
[DataMember]
public string Sex { get; set; }
[DataMember]
public AddressData Address { get; set; }
[DataMember]
public ContactDetailData ContactDetail { get; set; }
[DataMember]
public MembershipData Membership { get; set; }
int IIdentifiableEntity.EntityId
{
get { return MemberID; }
set { MemberID = value; }
}
}
public class AddressData
{
public int MemberID { get; set; }
public int AddressType { get; set; }
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string AddressLine3 { get; set; }
public string PostCode { get; set; }
public string City { get; set; }
public string County { get; set; }
public string Town { get; set; }
public string Country { get; set; }
public MemberData Member { get; set; }
}
do I need to do anything additional
While you don't need to use the DataMember attribute to decorate your service types (WCF will still serialize them, as long as they only contain serializable types), you should generally still use the attribute.
From https://stackoverflow.com/a/4836803/569662:
- without [DataContract], you cannot define an XML namespace for your data to live in
- without [DataMember], you cannot serialize non-public properties or fields
- without [DataMember], you cannot define an order of serialization (Order=) and the DCS will serialize all properties alphabetically
- without [DataMember], you cannot define a different name for your property (Name=)
- without [DataMember], you cannot define things like IsRequired= or other useful attributes
- without [DataMember], you cannot leave out certain public properties - all public properties will be serialized by the DCS