Programmatically extend a service host

May 10, 2010 at 9:36 AM

Hi there in my project i configurate the serviceHost in code such like:

ServiceHost myServiceHost;

List<Uri> endpointUriList = new List<Uri>();

endpointUriList.Add(new Uri(String.Format("net.tcp://localhost:{0}/{1}", tcpPort, serviceEndpointName))); 

myServiceHost = new ServiceHost(serviceType, endpointUriList.ToArray());

//Remove existing ServiceDebugBehaviors
myServiceHost.Description.Behaviors.Remove(myServiceHost.Description.Behaviors.First((x) => (x.GetType() == typeof(ServiceDebugBehavior))));

//Behavior for MEX endpoint   
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = httpPort != null;
behavior.HttpsGetEnabled = httpsPort != null;

//Behavior for tcp endpoint
ServiceDebugBehavior debugBehavior = new ServiceDebugBehavior();
debugBehavior.IncludeExceptionDetailInFaults = true;

//Filter for remote logging
WCFChannelLogger filter = new WCFChannelLogger();

//Add behaviors to service host
myServiceHost.Description.Behaviors.Add(behavior);
myServiceHost.Description.Behaviors.Add(debugBehavior);
myServiceHost.Description.Behaviors.Add(filter);


// Create basicTcpBinding endpoint 
NetTcpBinding tcpBinding = new NetTcpBinding
{
 Name = "netTcp",
 ReceiveTimeout = receiveTimeout,
 SendTimeout = sendTimeout,
 MaxBufferPoolSize = maxBufferPoolSize,
 MaxReceivedMessageSize = maxReceivedMessageSize,
 MaxBufferSize = maxBufferSize
};

System.ServiceModel.Channels.Binding mexTcpBinding = MetadataExchangeBindings.CreateMexTcpBinding();

myServiceHost.AddServiceEndpoint(typeof(IMetadataExchange), mexTcpBinding, "mex");

myServiceHost.Open();

 

Can you tell me where an how i have to add it there? Please...

Thanks for you answere