Raghavendra Devraj
Raghavendra Devraj

Reputation: 457

how to check data member is serialized or not in WCF?

In C# WCF which elements get serialized when we send data to an application? When a variable has the attribute [Data member] does that variable get serialized? I don't know exactly. And how would you check to see if the data member is serialized or not? Can any one explain with an example?

Upvotes: 0

Views: 1359

Answers (3)

Steven Padfield
Steven Padfield

Reputation: 644

You need to put DataContractAttribute on your class, and DataMemberAttribute on any properties you wish to have serialized.

Here is an example data contract:

[DataContract]
public class MyType
{
    // This property is serialized to the client.
    [DataMember]
    public int MyField1 { get; set; }

    // This property is NOT serialized to the client.
    public string MyField2 { get; set; }
}

Upvotes: 1

Jobert Enamno
Jobert Enamno

Reputation: 4461

Basically all public properties of your returned object are serialized but only those properties that have attribute DataMember are visible or exposed to your client application without this attribute you cannot access them from your client.

Upvotes: 0

Kirk Broadhurst
Kirk Broadhurst

Reputation: 28728

The following members are normally serialized

  • any public property with both a get and set accessor
  • any property marked as DataMember

Upvotes: 1

Related Questions