Saturday, June 09, 2007

DataContract Vs. Service Contract

Hi All,
In WCF,Some new terminolgies are come up for .Net Developers,but not for COM,DCOM developers,Since the developers who are familiar with developing Dist. Application used to divide their code to interface and implementations.

The same concept is exist on WCF Tech.,Since the devleopers should divide his servce to :
1- Data 2- Operations.

**Data represented by creating DataContract which expose the data which will be transefered /consumend from the serive to its clients.

**Operations which is the functions provided by this service.

To write an operation on WCF,you have to write it as an interface,This interface contains the "Signature" of the methods tagged by ServiceContract attribute,and all methods signature will be impelemtned on this interface tagged with OperationContract attribute.

and to implement these serivce contract you have to create a class which implement the interface and the actual implementation will be on that class.

Code Below show How to create a Service Contract:

Public Interface IEmpOperations
Decimal Get EmpSal(int EmpId);


Class MyEmp: IEmpOperations
Decimal Get EmpSal()
// Implementation of this method.

Hope now you can differentiate between Data Contract,Service Contract and OperationContract.

Moustafa arafa
Post a Comment