Outils pour utilisateurs

Outils du site


cours:app_rep_orientees_service_2016_2017:lab_contract

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
cours:app_rep_orientees_service_2016_2017:lab_contract [2018/03/28 22:08]
tigli créée
cours:app_rep_orientees_service_2016_2017:lab_contract [2019/04/24 07:57] (Version actuelle)
tigli [References]
Ligne 1: Ligne 1:
  
-===== Type of Contracts =====+==== Few reminders about WCF ABC Model   ==== 
 + 
 +The ABC of Windows Communication Foundation 
 + 
 +"​ABC"​ is the WCF mantra. "​ABC"​ is the key to understanding how a WCF service endpoint is composed. Think Ernie, Bert, Cookie Monster or Big Bird. Remember "​ABC"​. 
 + 
 +  * "​A"​ stands for Address: Where is the service? 
 +  * "​B"​ stands for Binding: How do I talk to the service? 
 +  * "​C"​ stands for Contract: What can the service do for me? 
 + 
 +Web services zealots who read Web Service Description Language (WSDL) descriptions at the breakfast table will easily recognize these three concepts as the three levels of abstraction expressed in WSDL. So if you live in a world full of angle brackets, you can look at it this way: 
 + 
 +  * "​A"​ stands for Address—as expressed in the wsdl:​service section and links wsdl:​binding to a concrete service endpoint address. 
 +  * "​B"​ stands for Binding—as expressed in the wsdl:​binding section and binds a wsdl:​portType contract description to a concrete transport, an envelope format and associated policies. 
 +  * "​C"​ stands for Contract—as expressed in the wsdl:​portType,​ wsdl:​message and wsdl:type sections and describes types, messages, message exchange patterns and operations. 
 + 
 +"​ABC"​ means that writing (and configuring) a WCF service is always a three-step process: 
 + 
 +  * You define a contract and implement it on a service 
 +  * You choose or define a service binding that selects a transport along with quality of service, security and other options 
 +  * You deploy an endpoint for the contract by binding it (using the binding definition, hence the name) to a network address. 
 + 
 +===== Contracts ​in WCF =====
  
 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 **: 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 **:
  
 +  * Service contract
   * Data Contract   * Data Contract
-  * OperationContract+  * Operation Contract
   * Fault Contract   * Fault Contract
   * Message Contract ​   * Message Contract ​
Ligne 11: Ligne 34:
 we've already used Data Contract and Operation 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 messageBut there are scenarioswhen we need more control ​over SOAP messageSoMessageContract is the answer in such cases.+== Service contract and Operation Contract == 
 + 
 +Service contracts define the Interface for the service 
 + 
 +An Operation Contract defines the method exposed to the client to exchange the information between ​the client ​and server. An Operation Contract describes what functionality is to be given to the client, such as addition, subtraction and so on. 
 + 
 +[[http://​www.wcftutorial.net/​Service-Contract.aspx|Getting Started with this step by step tutorial]] 
 + 
 +== Data Contract == 
 +Data Contracts define the data type for variables ​that are the same as get and set properties but the difference ​is that a Data Contract in WCF is used to serialize and deserialize ​the complex dataIt defines how data types are serialized and deserialized. Using serializationyou can convert an object into a sequence of bytes that can be transmitted ​over a networkUsing de-serializationyou reassemble an object from a sequence of bytes that you receive from a calling application.  
 + 
 +[[http://​www.wcftutorial.net/​Data-Contract.aspx|Getting Started with this step by step tutorial]]
  
 ==  Fault Contract == ==  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. ​+A Fault Contract handles the exception and understands the cause of the error that occurs in the WCF service. When we develop a managed application or service, we will handle the exception ​using a try- catch block, but these exceptions handlers are technology-specific. 
 + 
 +[[http://​www.wcftutorial.net/Fault-Contract.aspx|Getting Started with this step by step tutorial]] 
 + 
 +== Message Contract ==  
 + 
 +The default SOAP message format ​is provided by the WCF runtime for communication between the client and the serviceIf it does not meet your requirements then we can create our own message formatThis can be done using the Message Contract attribute. 
 + 
 +==== Exercices on Contracts ==== 
 + 
 +=== Exercice on DataContract,​ Service Contract and Operation Contract === 
 +Create a calculator service that implement add and sub operations on complex numbers instead of numerical ones. 
 +This justifies to introduce DataContract for the Complex number Type.  
 + 
 +=== Exercice on Fault Contract === 
 +In the Add operation, throw general exception and send exception information from service to client ​with FaultException. 
  
-** 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 22:08 par tigli