Saturday, June 09, 2007

DataContract attribute in WCF

Hi Folks,
This is the First post of WCF in my blog,i was little busy with Team System Blogging :),anyway,let's assure one of the first important aspects of WCF programming which is "Contract First" Approach,This approach let the developer or Architect to design his service before starting developing it.
First thing you will do when you create a WCF is creating the Data Contract,which is the Contract that specifies the data will be exchanged between the service and it clients,suppose we need to create a WCF serice which expose Employee Data,The Data Contract will be as follows:

namespace Emp
{

[DataContract]
Class Employee
{
[DataMember]
int EmpId;

[DataMember]
string EmpName;

[DataMember]
string DeptName;
}
}

DataMember attribute you have to put it on each data member in the class in case you want to serialize and deserialize this member which is used on passing or retireving data from this data contract.

DataContract Attribute can be applied on :
1) Classes.
2) Enumerations.
3) Structures.


Hope This helps.

Regards,
Moustafa arafa

1 comment:

Unknown said...

BTW :
Get started with WCF, By Reading "Windows Communication Foundaiton Step By Step" - MS Press Book,Author : John Sharp

i like it............its cool book