QuickStart Series--wcf--04 metadata and exception handling

Source: Internet
Author: User

This chapter will be metadata and exception handling introduction, this part of the concept of relatively strong, can be a quick look at the good.

The client and the server communicate with the endpoint, and the provider publishes the service through one or more endpoints, and the consumer of the service makes the call to the service by creating the endpoint that matches it. The service's metadata can be seen as a description of all its endpoints, which describe all of the endpoint information for the service in an easy-to-exchange data format (WSDL, XSD, Ws-policy). WCF provides a complete metadata architecture that is easy to export, publish, Fetch, and import of meta data.

The metadata for a service is actually a description of the endpoints it has, and the endpoints consist of three elements of address, binding, and contract. The address determines the location of the service and implements the appropriate addressing mechanism, the contract describes the message exchange pattern and the structure of the message, the binding through the creation of a channel stack to encode, transmit, and based on some special functions of the detailed message processing.

WCF is a distributed communication platform based on SOA, and an important feature of SOA is the implementation of cross-platform interoperability, the metadata itself adopts open standards, including: XSD, in the form of XML Schema description of the message, WSDL, a complete WSDL document to a full description of the service The Ws-policy strategy, which describes the capabilities and features of the service in the form of assertions through the Ws-policy specification. Next, a brief introduction to Ws-mex is the WS specification for metadata Exchange.

Ws-policy: Provides standards for business-agnostic behavior and capabilities, such as transaction flow, reliable message transmission, and transport security.

Ws-transfer: Provides a unified specification for the basic operation of addressable Web service resources, such as manipulating Web resources through Get,put,delete and create.

WSDL: It defines a Web service as a collection of endpoints, and each endpoint contains a series of message-based operations. Its content mainly contains 5 large sub-elements: type, oh that over XSD representation of the data type; Message, the carrier of the communication data; PortType, a collection of service operations; binding, message, operation and protocol, format bindings; Service, collection of related endpoints

For Ws-mex, the obtained metadata is encapsulated in the Reply Message topic Section <Metadata> node, which is a collection of <MetadataSection> Next, you'll see the relationship between metadata and metadatasection and the three typical metadata dialects through a chart.

WCF metadata Schema Model: WCF exposes a service through an endpoint, and metadata helps the consumer of the service effectively interact with the endpoint to make normal calls to the service. It helps code generation tools like SvcUtil.exe to efficiently generate client code and configuration, as shown in the overall structure.

Metadata export: The list of WCF service-related endpoints is converted to Metadataset objects, and the export of metadata is implemented by System.ServiceModel.Description.MetadataExporter.

Metadata publishing: Converting the exported Metadataset object to an addressable metadata resource, published through the relevant protocols, Ws-mex and Http-get are two common protocols, The publication of metadata is implemented through the System.ServiceModel.Description.ServiceMetadataBehavior service behavior.

Metadata acquisition: Gets the published metadata resource through the relevant protocol (Ws-mex or Http-get) and transforms it into a Metadataset object. The acquisition of metadata is implemented through system,servicemodel.description.metadataexchangeclient.

Metadata import: The Metadataset object generated by the obtained metadata resource is eventually converted to an endpoint object, implemented through System.ServiceModel.Description.MetadataImporter.

This section mainly deals with the exception handling model provided by WCF and the analysis of the underlying implementation of WCF exception handling, including the serialization and deserialization of exceptions, the propagation of exceptions, the masking of exceptions, and so on. For non-distributed single-process applications, exception handling is simply throwing exceptions and catching exceptions. However, the WCF outcome is the interconnection between the related systems, interconnected systems need to cross-process, cross-and cross-network interaction, exception handling becomes relatively complex, including the following elements.

Exception Marshaling (Exception marshaling): How the exception thrown by the server is serialized so that it can be passed to the client.

Masking of sensitive information (sensitive information shielding): Exceptions that are thrown often contain sensitive information, directly returning the exception thrown by the service operation execution process directly to the client, there is a large security risk.

System integration and interoperability: Based on the effective inheritance and interoperation between different vendors and technology platform systems, new requirements for exception handling are also proposed, which require standardization of exception messages.

By default, if an exception is thrown during a service operation, its true exception details are limited to the server-side visibility, and in the debug phase, detailed exception information can be sent with the following settings.

1<system.serviceModel>2<behaviors>3<serviceBehaviors>4<behavior name="Servicedebugbehavior">5<servicedebug includeexceptiondetailinfaults="true"/>6</behavior>7</serviceBehaviors>8</behaviors>9<services>Ten<service behaviorconfiguration="Servicedebugbehavior"></service> One</services> A</system.serviceModel>
View Code

It can also be resolved by setting the [ServiceBehavior (includeexceptiondetailinfaults=true)] feature.

In WCF, all exception information is propagated through the FaultException class, and the custom information can be propagated through its generic parameter <TDetail>. In the contract, it can be implemented by setting the relevant properties in Faultcontractattribute, including: Action, Detailtype, Name&namespace, hasprotection& ProtectionLevel.

And the previous chapter refers to the message used to propagate the SOAP message, for exception information, WCF propagates through the Faultmessage object, whose objects include the following properties: Code, which represents the error code; Reason, which indicates the cause of the error; Represents the SOAP node that caused the error; role represents the roles that the SOAP node corresponds to; detail represents a detailed description of the error.

WCF does not directly exchange between FaultException exceptions and error messages. It is done by a System.ServiceModel.Channels.MessageFault object, and the formatting of the message is done by Faultformatter. Because the inheritance of Ehab is inconvenient, it is not introduced.

Resources:

[1] Jing Jinnan . WCF fully parses [M]. Shanghai : Electronic Industry Publishing house ,.

QuickStart Series--wcf--04 metadata and exception handling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.