The second chapter summarizes the WCF contract

This chapter covers a lot of background contract, which is the basis for interoperability. Contract accurately describe a message service can understand.

WCF SOAP high utilization in the contract definition. In particular, it uses WSDL to describe the service endpoint, use XSD to describe the data. Service operation defined in the WSDL is used at run time to forward the received request to the correct .NET class. Similar, XML files defined by the XSD contract is deserialized into .NET type at run time and sent to the service operation. Combined, WSDL and XSD definitions provide services to achieve the implementation of a standards-based .NET type.

Detailed definition of the three types of contracts:

Service contract. Service contracts describe the functional operations implemented by the service.

Data contract. Data communication service contract describes the data structure depends. A data contract the CLR type sequence into XML data and strict selection of their members.

Message contracts. Contract with the message type and non-typed data and provides accurate control of the SOAP message header and a message body.

Service contract

Service contracts define service operations - Method class service interfaces exposed. They provide a formal WSDL interface to a service. Service contract and [OperationContract] properties are defined by [ServiceContract]. Operation name inherited from class and method names can be overloaded in the definitions of these attributes when. Service contract supports three message exchange patterns: request - response, one-way and duplex.

Request - Reply operation contract blocking calls in the client, before obtaining execution control client will wait for the server to complete the operation. Therefore, they should only be used for the user is willing to wait a relatively quick feedback service call. In the client, .NET asynchronous invocation patterns can be applied in a request - reply message exchange pattern to prevent the client is blocked long wait service call.

One-way operation contract, as the name implies, one-way; they do not return the results to the end customer. The service operator must have a null return type and is marked as [IsOneWay = true] at [the OperationContract] in. Contract unidirectional transmission protocol can be implemented in any further including MSMQ.

Two-way operation contract offers the best scalability and performance because they have requested in pairs and reply operation on the client and server. The client and the server picked up after a good two-way channel, client and server can initialize a message. This time, the total mode is ideal for client notification.

Data contract

Data contracts define application data interface services. Labeled [the DataContract] classes and [the DataMember] attributes contained in the XML metadata definition, they are used as part of a WSDL service contract represented. Other types of data may be exposed in the WSDL, such as those of the base type and tagged [the Serializable] type. Because [the DataContract] sequence designed for the interoperability rules, it is the best sequence in WCF structure.

Class members by [the DataMember] attribute data included in the contract. This is a rigorous selection model so only use this attribute members will be included in the contract. This also makes it [the DataContract] with respect to [the Serializable] referred to a more suitable sequence structure, as the latter will cause the internal structure is exposed to an external service.

Hierarchy support classes and their namespace also through this hierarchy are included. In order to support multi-state and contains a collection of objects, WCF service to use to publish a list of known types. Data also designed a version of the contract. When adding a new member to a data contract, existing clients will continue to work to provide special rules are allowed.

Message contracts

Contract message to permitting operation contract SOAP header and body. Message can be used [the DataContract] or [the Serializable] be typed, or they may be a simple type of message. Type of message is defined by [the MessageHeader] and [MessageBody] property. During the design phase of the message data may be undefined, which provides maximum scalability. Untyped can access a SOAP message header and a message body.

===============

forward from

 

Reproduced in: https: //www.cnblogs.com/llbofchina/archive/2011/06/27/2091405.html

Guess you like

Origin blog.csdn.net/weixin_33895016/article/details/94206783