6 March 2014

Service Contract

         Service contract describes the operation that service provides. A Service can have more than one service contract but it should have at least one Service contract.
            
          Service Contract can be define using [Service Contract] and [Operation Contract] attribute. [Service Contract] attribute is similar to the [Web Service] attribute in the Web Service and [Operation Contract] is similar to the [Web Method] in Web Service.
  • It describes the client-callable operations (functions) exposed by the service
  • It maps the interface and methods of your service to a platform-independent description
  • It describes message exchange patterns that the service can have with another party. Some service operations might be one-way; others might require a request-reply pattern
  • It is analogous to the element in WSDL
       To create a service contract you define an interface with related methods representative of a collection of service operations, and then decorate the interface with the Service Contract Attribute to indicate it is a service contract. Methods in the interface that should be included in the service contract are decorated with the Operation Contract Attribute.
Service contract describes the operation that service provides.
     
        A Service can have more than one service contract but it should have at least one Service contract.Service Contract can be define using [Service Contract] and [Operation Contract] attribute. [Service Contract] attribute is similar to the [Web Service] attribute in the Web Service and [Operation Contract] is similar to the [Web Method] in Web Service.
  • It describes the client-callable operations (functions) exposed by the service
  • It maps the interface and methods of your service to a platform-independent description
  • It describes message exchange patterns that the service can have with another party. Some service operations might be one-way; others might require a request-reply pattern
  • It is analogous to the element in WSDL
       To create a service contract you define an interface with related methods representative of a collection of service operations, and then decorate the interface with the Service Contract Attribute to indicate it is a service contract. Methods in the interface that should be included in the service contract are decorated with the Operation Contract Attribute.
  

 [Service Contract()]
    Public interface ISimpleCalculator
    {
        [Operation Contract ()]
        int Add (int num1, int num2);
    }  
    Once we define Service contract in the interface, we can create implement class for this interface.

Public class SimpleCalculator: IsimpleCalculator
 {
     Public int Add (int num1, int num2)
        {
            Return num1 + num2;
        } 
    }

     Without creating the interface, we can also directly created the service by placing Contract in the implemented class. But it is not good practice of creating the service
[Service Contract ()]
 Public class SimpleCalculator
 {
    [Operation Contract ()]
    Public int Add (int num1, int num2)
    {
         Return num1 + num2;
      } 
   }




No comments:

Post a Comment