Search code examples
wcfwcf-binding

what is the contract in webhttpbinding endpoint?


when creating a WCF RESTful service, part of the configuration includes creating a service endpoint. Something like the below

  <service name="MyService" behaviorConfiguration="serviceBehavior">
    <endpoint address="" binding="webHttpBinding" bindingConfiguration="UsernameWithTransport" contract="IMyService" behaviorConfiguration="web"></endpoint>
  </service>

My question is, what exactly is the contract provided for? Does it provide some sort of information to the browser that tries to access it?


Solution

  • In WCF The contract (ContractDescription) is a collection of operations that specifies what the endpoint communicates to the outside world. Each operation is a message exchange. For example, a request message and an associated reply message form a request/reply message exchange.

    A ContractDescription object is used to describe WCF contracts and their operations. Within a ContractDescription, each contract operation has a corresponding OperationDescription that describes aspects of the each operation that is part of the contract, such as whether the operation is one-way or request/reply. Each OperationDescription also describes the messages that make up the operation using a MessageDescriptionCollection. ContractDescription contains a reference to an interface that defines the contract using the programming model. This interface is marked with ServiceContractAttribute and its methods that correspond to endpoint operations are marked with the OperationContractAttribute.

    The contract is also important because you can expose distinct service contracts in a single WCF service.