Is it on the client side?
If so, you need to instantiate WsHttpBinding and EndpointAddress, and then pass the two to the client proxy constructor, which takes these two as parameters.
// using System.ServiceModel; WSHttpBinding binding = new WSHttpBinding(); EndpointAddress endpoint = new EndpointAddress(new Uri("http://localhost:9000/MyService")); MyServiceClient client = new MyServiceClient(binding, endpoint);
If this is server-side, you need to programmatically create your own instance of ServiceHost and add the appropriate service endpoints to it.
ServiceHost svcHost = new ServiceHost(typeof(MyService), null); svcHost.AddServiceEndpoint(typeof(IMyService), new WSHttpBinding(), "http://localhost:9000/MyService");
Of course, you can have several service endpoints added to your host service. Once you're done, you need to open the service host by calling the .Open () method.
If you want to be able to dynamically - at run time - select which configuration to use, you can define several configurations, each with a unique name, and then call the appropriate constructor (for your service host or your proxy client) with the configuration name that you want to use.
eg. you can easily:
<endpoint address="http://mydomain/MyService.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IASRService" contract="ASRService.IASRService" name="WSHttpBinding_IASRService"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="https://mydomain/MyService2.svc" binding="wsHttpBinding" bindingConfiguration="SecureHttpBinding_IASRService" contract="ASRService.IASRService" name="SecureWSHttpBinding_IASRService"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="net.tcp://mydomain/MyService3.svc" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IASRService" contract="ASRService.IASRService" name="NetTcpBinding_IASRService"> <identity> <dns value="localhost" /> </identity> </endpoint>
(three different names, different parameters, specifying different Configurations bindings), and then simply select the correct one to create an instance of your server (or client proxy).
But in both cases - the server and the client - you must choose before actually creating the service host or proxy client. Once created, they are immutable - you cannot tune them after they run.
Mark