Use of DataMember in WCF

Posted by Syedshakeer under WCF on 11/26/2011 | Points: 10 | Views : 12456 | Status : [Member] | Replies : 1
Hi,
What is the use of DataMember in WCF? Below is the code of Declaring DataMember.Where i Can use (or) call this datamember in WCF Programming.
Can you give a simple example of using DataMember...

[DataContract]
public class MyDataContract
{

[DataMember]
public string name = "myname";

[DataMember(IsRequired = true)]
public int age;

}


Syed Shakeer Hussain


Responses

Posted by: debal_saha-9451 on: 11/26/2011 [Member] Starter | Points: 25

Up
0
Down
DataMember attribute is required to expose the data along with contract of wcf services . If you don't use [ Datamember ] , then service can't able to transfer data(properties or fields). Use Using System.Runtime.Serialization to add datamember .
You can also use annotations like the below code .
[DataMember(Name = "NoteID", IsRequired = true)]
public int NoteID
{ get; set; }
Suppose, you are doing a CRUD application using SQL database . Using code you have to update database , at that time you should create a class which contains all the properties (respective to your database table's column name ) then use datamember attribute .
See the example :
http://www.dotnetfunda.com/articles/article279.aspx


Syedshakeer, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response