cours:app_rep_orientees_service_2016_2017:lab_contract
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
cours:app_rep_orientees_service_2016_2017:lab_contract [2019/04/23 22:03] – tigli | cours:app_rep_orientees_service_2016_2017:lab_contract [2019/04/24 05:57] (Version actuelle) – [References] tigli | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ===== Type of Contracts ===== | + | ==== Few reminders about WCF ABC Model ==== |
+ | |||
+ | The ABC of Windows Communication Foundation | ||
+ | |||
+ | " | ||
+ | |||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | |||
+ | 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: | ||
+ | |||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | |||
+ | " | ||
+ | |||
+ | * 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 | ||
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 | ||
* Operation Contract | * Operation Contract | ||
Ligne 11: | Ligne 34: | ||
we've already used Data Contract and Operation Contract. | we've already used Data Contract and Operation Contract. | ||
+ | |||
+ | == 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:// | ||
+ | |||
+ | == 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 data. It defines how data types are serialized and deserialized. Using serialization, | ||
+ | |||
+ | [[http:// | ||
== Fault Contract == | == Fault Contract == | ||
||| | ||| | ||
- | In WCF (Windows Communication Foundation), | + | A Fault Contract |
+ | [[http:// | ||
== Message Contract == | == Message Contract == | ||
- | DataContract has limited control over the SOAP message | + | The default |
+ | |||
+ | ==== 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 " | ||
- | * 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, | ||
- | * 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.1556056999.txt.gz · Dernière modification : 2019/04/23 22:03 de tigli