Outils pour utilisateurs

Outils du site


cours:app_rep_orientees_service_2016_2017:lab_contract

Ceci est une ancienne révision du document !


Type of Contracts

A contract is an agreement between two parties. It defines how a client should communicate with your service. In other words a contract is a platform and standard way of describing what the service does. There are the following four types of contracts in WCF Service Contract :

  • Data Contract
  • OperationContract
  • Fault Contract
  • Message Contract

we've already used Data Contract and Operation Contract.

Message Contract

DataContract has limited control over the SOAP message and all that control is related to contents inside body of the SOAP message. But there are scenarios, when we need more control over SOAP message. So, MessageContract is the answer in such cases.

Fault Contract

In WCF (Windows Communication Foundation), we will not expose exception directly to client if it occurs at service level. Fault Contract is used to return error details to the other party i.e. client.

Tutorial

  • Add to your calculator WS an exception … for example add “divide” operation and threw an exception on division by zero: throw new Exception(“Exception occurred at service level : Divide by zero”);
  • Test it without Fault Contract (with your Graphical Test Client extended to divide numbers). What happens ?
  • To integrate a more meaning full exception, you can add a Fault Contract following these steps :
    • Add [FaultContract(typeof(CustomFaultDetails))]in your [Service Contract]
    • and then use it in your code ..
      • CustomFaultDetails ex = new CustomFaultDetails();
      • ex.ErrorID = “12345“;
      • ex.ErrorDetails = “Specific error details here.“;
      • throw new FaultException(ex,“Reason: Testing…..“);
  • Test it without Fault Contract (with your Graphical Test Client extended to divide numbers). What happens ?
cours/app_rep_orientees_service_2016_2017/lab_contract.1522267721.txt.gz · Dernière modification : 2018/03/28 20:08 de tigli