What Are Contracts In WCF


  • 29 Jun, 2012

    Service Contracts : Attribute on class

    1) Operation contract : Attribute on method

    2) Data contract : attribute on method

    3) Message Contract : attribute on method

    4) Fault contract : attribute on method

    Comments Received:
    Please give your suggestions and feedback:
  • 10 Mar, 2012

    In WCF, all services expose contracts. The contract is a platform-neutral and standard way of describing what the service does.WCF defines four types of contracts.Service contractsDescribe which operations the client can perform on the service.There are two types of Service Contracts.ServiceContract - This attribute is used to define the Interface.OperationContract - This attribute is used to define the method inside Interface.[ServiceContract]interface IMyContract{ [OperationContract] string MyMethod( );}class MyService : IMyContract{ public string MyMethod( ) { return "Hello World"; }}Data contractsDefine which data types are passed to and from the service. WCF defines implicit contracts for built-in types such as int and string, but we can easily define explicit opt-in data contracts for custom types.There are two types of Data Contracts.DataContract - attribute used to define the classDataMember - attribute used to define the properties.[DataContract]class Contact{ [DataMember] public string FirstName; [DataMember] public string LastName;}If DataMember attributes are not specified for a properties in the class, that property can't be passed to-from web service.Fault contractsDefine which errors are raised by the service, and how the service handles and propagates errors to its clients.

    Comments Received:
    Please give your suggestions and feedback:

2009-2016 downloadmela.com. All rights reserved.