WCF Technical Analysis 25: Metadata (Metadata) Architecture panorama Presentation [metadata description]

Source: Internet
Author: User
Tags definition resource xml attribute wsdl

In [WS Standard article] I have devoted a great part of the Ws-mex and the WS specification associated with it: Ws-policy, Ws-transfer, and WSDL, because the WCF Meta data structure system is based entirely on the relevant specifications of Ws-mex. Familiarity with these basic WS specifications is of great significance for our comprehensive and profound understanding of WCF's entire metadata architecture system. Not only for metadata, but for subsequent chapters, such as transactions, reliable sessions, security, and so on, I strongly recommend that the reader make a general understanding of the WS specification before making a formal study of the relevant parts.

Through the introduction of Ws-mex, we know that the metadata obtained is encapsulated into the <Metadata> node of the reply message body, whether it is a ws-transfer get operation or getting Metadata operation, and <metadata > is a collection of a set of <MetadataSection> elements. In the managed world, the,<metadatasection> element and the <MetadataSection> element collection have the corresponding types to represent, That's the metadatasection and Metadataset we're going to focus on next.

First, Metadatasection

Metadatasection is defined under the System.ServiceModel.Description namespace to be used to define metadata based on a dialect (dialect) that contains metadata SOAP message bodies < The metadatasection> node matches. Let's look at the definition of metadatasection now:

1: [XmlRoot (Elementname= "metadatasection", namespace= "Http://schemas.xmlsoap.org/ws/2004/09/mex")]
2:public class Metadatasection
3: {
4://other Members
5:public metadatasection ();
6:public metadatasection (String dialect, string identifier, object metadata);
7:
8: [XmlAnyAttribute]
9:public collection<xmlattribute> Attributes {get;}
[XmlAttribute]
11:public string dialect {get; set;}
: [XmlAttribute]
13:public string Identifier {get; set;}
[XmlElement ("Location", typeof (Metadatalocation), namespace= "Http://schemas.xmlsoap.org/ws/2004/09/mex")]
: [XmlElement ("Metadatareference", typeof (Metadatareference), namespace= "http://schemas.xmlsoap.org/ws/2004/09/" Mex ")]
[XmlElement ("Metadata", typeof (Metadataset), namespace= "Http://schemas.xmlsoap.org/ws/2004/09/mex")]
[XmlElement ("Schema", typeof (XmlSchema), Namespace = "Http://www.w3.org/2001/XMLSchema")]
[XmlElement ("Definitions", typeof (ServiceDescription), Namespace = "http://schemas.xmlsoap.org/wsdl/")]
: [XmlAnyElement]
20:public object Metadata {get; set;}
21st:
22://Four predefined meta data dialects (dialect)
//mex:http://schemas.xmlsoap.org/ws/2004/09/mex:
24:public static string Metadataexchangedialect {get;}
://ws-policy:http://schemas.xmlsoap.org/ws/2004/09/policy
26:public static string Policydialect {get;}
://wsdl:http://schemas.xmlsoap.org/wsdl/
28:public static string Servicedescriptiondialect {get;}
://xml Schema:http://www.w3.org/2001/xmlschema
30:public static string Xmlschemadialect {get;}
31:}

But look at the definition of metadatasection, you may feel that there is not much to pay attention to, if the combination of Ws-mex norms, there are a lot of interesting places to ponder:

First, a XmlRootAttribute attribute is applied on the type, and the name and namespace defined are: Metadatasection and Http://schemas.xmlsoap.org/ws/2004/09/mex respectively. This fits perfectly with Ws-mex 1.1.

Second, the attribute dialect expresses the metadata dialect, and you can define any string as its property value. The Ws-mex defines five predefined meta data dialects: MEX, XML Schema, WSDL, Ws-policy, and ws-policy attachment. In addition to the Ws-policy attachement,metadatasection defines a static read-only property for the first four, so that the aspect is programmed to use.

Then, the attribute identifier represents the identifier of the metadata, a string in the form of a URI, which, due to space limitations, is not mentioned in the previous introduction to Ws-mex, and interested readers can refer to the 4th part of the Ws-mex official document. Identifier and dialect are eventually serialized to generate the corresponding attributes of the <MetadataSection> element. In addition, Metadatasection also defines the attributes attribute of type collection<xmlattribute>, you can customize any XML attribute, and will end up as a <metadatasection The properties of the > element.

When the contents of the metadata are contained in the attribute metadata, when the entire metadatasection is serialized, the value of the property is serialized into an XML element, and the name and namespace of the element are determined by the specific type. From a series of xmlelementattribute attributes applied to this property, we can see that the metadatasection defines the corresponding name and namespace for several special types:

Metadatalocation

Metadatalocation represents the address of a metadata document represented in RUI form, Ws-mex 1.1 stipulates that the URI of the metadata document address can be substituted for the content of the corresponding metadata. The metadatalocation definition is defined under the System.ServiceModel.Description namespace, as follows:

   1: [XmlRoot (Elementname= "Location", namespace= "Http://schemas.xmlsoap.org/ws/2004/09/mex")]
2:public class Metadatalocation
3: {
4: Public metadatalocation ();
5: Public metadatalocation (string location);
6:
7: [XmlText]
8: Public string Location {get; set;}
9:}

Metadatareference

In accordance with the Ws-addressing 2004 or Ws-addressing 1.0 specification, if the metadata becomes an addressable resource (addressable Resource), it can be referenced through an endpoint reference (Endpoint Reference) in a way that locates the resource. Ws-mex 1.1 provides the means by which metadata endpoint references can be substituted for the content of the corresponding meta data. Metadata endpoint references can be represented by metadatareference, metadatareference defined in the System.ServiceModel.Description namespace, as follows:

   1: [XmlRoot (elementname = "Metadatareference", Namespace = "Http://schemas.xmlsoap.org/ws/2004/09/mex")]
2:public class Metadatareference:ixmlserializable
3: {
4:
5: Public metadatareference ();
6: Public metadatareference (endpointaddress address, addressingversion addressversion);
7: Public endpointaddress Address {get; set;}
8: Public addressingversion addressversion {get; set;}
9:}

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.