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 ();