It Could Be Helpful For You Rajeev
Hi Rajeev,
Adding MEX endpoints programmatic:-
Like any other endpoint, you can only add a meta data exchange endpoint programmatically before opening the host. WCF does not offer a dedicated binding type for the meta data exchange endpoint. Instead, you need to construct a custom binding that uses the matching transport binding element, and then provide that binding element as a construction parameter to an instance of a custom binding. Finally, call the AddServiceEndpoint( ) method of the host providing it with the address, the custom binding, and the IMetadataExchangecontract type. Example shows the code required to add a MEX endpoint over TCP. Note that before adding the endpoint you must verify the presence of the metadata behavior.
Adding TCP MEX endpoint programmatically
BindingElement bindingElement =
new TcpTransportBindingElement( );
CustomBinding binding =
new CustomBinding(bindingElement);
Uri tcpBaseAddress =
new Uri("net.tcp://localhost:9000/");
ServiceHost host =
new ServiceHost(typeof(MyService),tcpBaseAddress);
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( );
Thanks
Ankit
Daccit Pvt Ltd
|