WCF Technical Analysis 27: How to publish a service into wsdl[programming article]

Source: Internet
Author: User
Tags definition bool http request wsdl

For WCF service-side metadata architecture, it is only half done by Metadataexporter the endpoint of a service into Metadataset (refer to the "How to export the metadata for WCF services"). The metadata represented by the Metadataset object, which is successfully exported, needs to be published as a network resource that can be accessed before it can be obtained by the service consumers, thereby effectively helping them to make service calls. The release of metadata is ultimately achieved through servicemetadatabehavior such a service behavior, let's first get to know ServiceMetadataBehavior.

One, the implementation of metadata publishing: ServiceMetadataBehavior

ServiceMetadataBehavior is a IServiceBehavior service behavior that implements a metadata publishing model based on the following two protocols:

http-get: Use HTTP protocol get operation, send HTTP request to metadata destination address, and represent the corresponding query parameter in the form of query string (querystring). The metadata is eventually returned as an HTTP reply;

Ws-mex: metadata Providers create endpoint publishing metadata according to the WS-MEX specification, and the metadata consumer creates an endpoint that is also based on Ws-mex to interact with it and eventually get metadata in the form of soap. For Ws-mex, you can refer to my article "Meta data (Metadata) Architecture panorama Presentation [WS Standard Chapter]"

We start with the following code to see the definition of ServiceMetadataBehavior, ServiceMetadataBehavior implement IServiceBehavior interface, The behavior of all published metadata is defined in the ApplyDispatchBehavior method.

1:public class Servicemetadatabehavior:iservicebehavior
2: {
3:
4://other Members
5:void iservicebehavior.addbindingparameters (servicedescription description, ServiceHostBase ServiceHostBase, collection<serviceendpoint> endpoints, bindingparametercollection parameters);
6:void Iservicebehavior.applydispatchbehavior (servicedescription description, ServiceHostBase ServiceHostBase);
7:void iservicebehavior.validate (servicedescription description, ServiceHostBase servicehostbase);
8:
9:public Uri externalmetadatalocation {get; set;}
10:
One://http
12:public bool httpgetenabled {get; set;}
13:public Uri Httpgeturl {get; set;}
14:public Binding httpgetbinding {get; set;}
15:
://https
17:public bool httpsgetenabled {get; set;}
18:public Binding httpsgetbinding {get; set;}
19:public Uri Httpsgeturl {get; set;}
20:
21:public metadataexporter metadataexporter {get; set;}
22:}

ServiceMetadataBehavior defines a set of properties for controlling specific metadata publishing behavior, most of which are based on the http-get release pattern. ExternalMetadataLocation represents an external metadata address that is returned to the client, either as an absolute address or as a relative address based on Httpgeturl or httpsgeturl representations ; Http-get metadata Publishing supports both HTTP and HTTPS in two forms, and HTTP (s) getenabled is a switch that controls whether to allow metadata publishing based on HTTP (s), HTTP (s) Geturl and HTTP (s) Getbinding This specifies the address and bindings used, and the Metadataexporter object represented by the Metadataexporter property is used for export of the metadata, and the default is Wsdlexporter.

You can configure all ServiceMetadataBehavior properties except Metadataexporter, and WCF also provides you with additional matching items to better control the publishing behavior of the metadata. For WCF developers or implementations, when you don't have a comprehensive document that guides you through the configuration of service behavior or endpoint behavior, you can view the behaviorextensionelement definition for that behavior to get all the configuration information associated with that behavior. ServiceMetadataBehavior related configuration items are all defined in servicemetadatapublishingelement, and the servicemetadatapublishingelement definition is given below:

1:public Sealed class Servicemetadatapublishingelement:behaviorextensionelement
2: {
3://other Members
4:public override Type Behaviortype {get;}
5: [ConfigurationProperty ("ExternalMetadataLocation")]
6:public Uri externalmetadatalocation {get; set;}
7:
8://http
9: [ConfigurationProperty ("httpgetenabled", DefaultValue = False)]
10:public bool httpgetenabled {get; set;}
One: [ConfigurationProperty ("Httpgeturl")]
12:public Uri Httpgeturl {get; set;}
[Stringvalidator (Minlength=0), ConfigurationProperty ("httpgetbinding", Defaultvalue= "")]
14:public string Httpgetbinding {get; set;}
: [ConfigurationProperty ("Httpgetbindingconfiguration", defaultvalue= ""), Stringvalidator (MinLength=0)]
16:public string Httpgetbindingconfiguration {get; set;}
17:
://https
: [ConfigurationProperty ("httpsgetenabled", DefaultValue = False)]
20:public bool httpsgetenabled {get; set;}
[ConfigurationProperty ("Httpsgeturl")]
22:public Uri Httpsgeturl {get; set;}
[Stringvalidator (Minlength=0), ConfigurationProperty ("httpsgetbinding", Defaultvalue= "")]
24:public string Httpsgetbinding {get; set;}
[Stringvalidator (Minlength=0), ConfigurationProperty ("Httpsgetbindingconfiguration", DefaultValue= "")]
26:public string Httpsgetbindingconfiguration {get; set;}
27:
[ConfigurationProperty ("Policyversion", defaultvalue= "Default"), TypeConverter (typeof) )]
29:public policyversion policyversion {get; set;}
30:}

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.