The export of metadata is the process of transforming from ServiceEndpoint object to Metadataset object, in the WCF metadata frame system, the export of metadata is realized by Metadataexporter. Metadataexporter is an abstract type that defines the basic behavior of exporting metadata. WCF defines a specific metadataexporter:wsdlexporter that generates a WSDL based metadataset based on the metadata export of an endpoint. Let's get to know Metadataexporter and Metadataset first.
First, Metadataexporter
Metadataexporter is an abstract type defined under the System.ServiceModel.Description namespace, and the following code fragment gives the definition of metadataexporter. Metadataexporter defines 3 methods associated with the metadata export, where exportcontract only exports metadata based on a service contract, and exportendpoint exports all the metadata related to an endpoint. Instead of directly returning the Metadataset object used to host metadata information, the two methods temporarily store the exported metadata in the context of the metadata transformation, eventually extracting the exported metadata from the metadata transformation context through the Getgeneratedmetadata method.
1:public Abstract class Metadataexporter
2: {
3: Public abstract void Exportcontract (ContractDescription contract);
4: Public abstract void Exportendpoint (ServiceEndpoint endpoint);
5: Public abstract Metadataset getgeneratedmetadata ();
6:
7: Public collection<metadataconversionerror> Errors {get;}
8: Public policyversion policyversion {get; set;}
9: Public Dictionary<object, object> state {get;}
10:}
In addition, the Metadataexporter defines three properties errors, policyversion, and state. Errors is a collection of Metadataconversionerror objects that contain errors or warning messages that occur during metadata export, which we can use to perform some of the corresponding exception handling The State of the dictionary type can be used as a container to hold some of the objects that you use dynamically during the metadata export process, whereas policyversion represents the version of the Ws-policy specification on which the metadata is based. The definition of policyversion is as follows, because the defined constructor is private, so the object cannot be created directly with the new operator. Ws-policy objects representing Ws-policy 1.2 and Policyversion 1.5 can be obtained only by defining the two static read-only properties in Policyversion Policy12 and POLICY15. The static property default represents the Ws-policy version, which is currently ws-policy 1.2. The property namespace represents the namespace of the corresponding Ws-policy version.
1:public Sealed class Policyversion
2: {
3: //other Members
4: Private Policyversion (string policynamespace);
5: Public static policyversion Default {get;}
6: Public string Namespace {get;}
7: Public static policyversion Policy12 {get;}
8: Public static policyversion Policy15 {get;}
9:}
WCF defines a specific metadataexporter type used to export endpoints as WSDL based Metadataset, or Wsdlexporter.
Second, Wsdlexporter
Through the introduction of the metadata (Metadata) architecture panorama [WS Standard article], we know that metadata has 33 main manifestations:XML Schema,ws-policy policy , and WSDL , and the WSDL can directly represent the data and message types used by the Web service using an XML schema, using a Ws-policy policy assertion to define its binding behavior, and basically a WSDL document can be used to represent all the information of a Web service.
Because WSDL is the language that describes Web services well at present, establishing the matching relationship between WCF endpoint and WSDL element, as well as the realization of metadata import and export based on the matching relationship, is one of the most important goals of WCF metadata framework system. In section 1th, in the introduction to WSDL, we have talked about the matching relationship between the three elements of the WCF endpoint (address, binding, and contract) and the 5 elements that make up a WSDL document (based on WSDL 1.1), and now we have a simple summary. The matching relationship between the 5 elements (Service, Binding, PortType, message, and type) that makes up the WSDL and the three elements of the endpoint is generally reflected in Figure 1 , where the arrows between the WSDL elements represent the reference relationship, The arrows between the WSDL and the servicepoint represent a matching relationship.
Fig. 1 The matching relationship between the elements of the WSDL and the three elements of the endpoint
From Figure 1 It is easy to see that a port element of a service element in WSDL actually represents the entire ServiceEndpoint object, and the address of the port is an endpoint ; the Binding element in the WSDL actually represents the same content as the binding of the endpoint, and the contract of the endpoint matches a PortType element.