Two Methods for publishing metadata of services

Source: Internet
Author: User

1. Display add service behavior, automatically providing HTTP-GET-based metadata for the service.
Once HTTP-GET-based Metadata Exchange is enabledHTTP base address. If everything is correct, you will get a service help page.
You can configure or program the service adding behavior.

Configuration method:

< System. servicemodel >
< Services >
< Service Name = "Myservice" Behaviorconfiguration = "Mexget" >
< Host >
< Baseaddresses >
< Add Baseaddress = "Http: // localhost: 10000" />
</ Baseaddresses >
</ Host >
</ Service >
</ Services >
< Behaviors >
< Servicebehaviors >
< Behavior Name = "Mexget" >
< Servicemetadata Httpgetenabled = "True" />
</ Behavior >
</ Servicebehaviors >
</ Behaviors >
</ System. servicemodel >

Programming:

Servicehost host =   New Servicehost ( Typeof (Myservice ), New Uri ( " Http: // localhost: 10000 " ));

Servicemetadatabehavior metadatabehavior;
Metadatabehavior = Host. description. behaviors. Find < Servicemetadatabehavior > ();
If (Metadatabehavior =   Null )
{
Metadatabehavior =   New Servicemetadatabehavior ();
Metadatabehavior. httpgetenabled =   True ;
Host. description. behaviors. Add (metadatabehavior );
}

Host. open (); 2. Use metadata exchange endpoints to publish metadata.
Publishing metadata with the Mex endpoint does not have to enable the HTTP-GET option, but does not affect even if enabled.
The contract used by the metadata exchange endpoint is Imetadataexchange , WCF automatically provides the implementation of this interface for the service host. Configuration method: < System. servicemodel >
< Services >
< Service Name = "Myservice" Behaviorconfiguration = "Mexget" >
< Host >
< Baseaddresses >
< Add Baseaddress = "Net. TCP: // localhost: 10000" />
< Add Baseaddress = "Net. Pipe: // localhost" />
</ Baseaddresses >
</ Host >
< Endpoint
Address = "Mex"
Binding = "Mextcpbinding"
Contract = "Imetadataexchange"
/>
< Endpoint
Address = "Mex"
Binding = "Mexnamedpipebinding"
Contract = "Imetadataexchange"
/>
< Endpoint
Address = "Http: // localhost: 10001/MEX"
Binding = "Mexhttpbinding"
Contract = "Imetadataexchange"
/>
</ Service >
</ Services >
< Behaviors >
< Servicebehaviors >
< Behavior Name = "Mex" >
< Servicemetadata />
</ Behavior >
</ Servicebehaviors >
</ Behaviors >
</ System. servicemodel > Programming: Bindingelement =   New Tcptransportbindingelement ();
Custombinding binding =   New Custombinding (bindingelement );

Uri tcpbaseaddress= NewUri ("Net. TCP: // localhost: 10000");
Servicehost host= NewServicehost (Typeof(Myservice ));

Servicemetadatabehavior metadatabehavior;
Metadatabehavior = Host. description. behaviors. Find < Servicemetadatabehavior > ();
If (Metadatabehavior =   Null )
{
Metadatabehavior =   New Servicemetadatabehavior ();
Host. description. behaviors. Add (metadatabehavior );
}
Host. addserviceendpoint ( Typeof (Imetadataexchange), binding, " MEX " );
Host. open ();

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.