WCF Data Contract and Data Member – Easy WCF
Skip to content

WCF Data Contract and Data Member

What is WCF Data Contract?

WCF Data Contract is a formal agreement between a service and client that defines the data to be exchanged. Data Contract can be either Implicit or Explicit.

Data Contract defines:

The Structure and Type of data for the message
External Format of Data passed to/from service
Defines how data types are Serialized or Deserialized
System.Runtime.Serialization assemblies in .net holds data contract and data members.

Serialization is a process of converting an object into XML and Deserialization is creating object from XML. Default, WCF uses DataContractSerialzer.

Let’s create a Project in Visual studio to understand it better.

  • Visual studio–>File–>project–>class Library–>Rename to CustomerService
  • Delete the default class Class1.cs and Add a WCF service and name it to Customer service.So CustomerService.cs and ICustomerService.cs would be created.
  • Add the Service Contract,Data Contract and Data members in ICustomerService.cs as given below.

In CustomerService.cs, let’s Implement the GetCustomerDetails method.

From client side, you can create a proxy of this service and test it.

© 2015, admin. All rights reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *