8

We have a service that has some settings that are supported only over net.tcp. What's the best way to add another endpoint? Do I need to create an entire new host?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Esteban Araya
  • 29,284
  • 24
  • 107
  • 141

4 Answers4

9

You can have multiple endpoints defined either on the server, or the client.

To do it on the client, you just need to edit your app.config file with a new endpoint with a different name, then define when you create your new client.

For example if you have an endpoint in your client app like:

<endpoint address="https://yourdomain.com/WCF/YourService.svc"
      binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IYourService"
      contract="MessagingService.IYourService"  
      name="BasicHttpBinding_IYourService" />

Which you call by:

YourServiceClient client = new YourServiceClient();

You can add a new endpoint with a new name:

<endpoint address="https://yourotherdomain.com/WCF/YourService.svc"
      binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IYourService"
      contract="MessagingService.IYourService"  
      name="BasicHttpBinding_IYourService_ENDPOINT2" />

Which you can call with:

YourServiceClient client = new YourServiceClient("BasicHttpBinding_IYourService_ENDPOINT2");

I just changed the domain above, but if you made a new binding configuration section, you could just change the "bindingConfiguration" value.

Dylan
  • 2,392
  • 6
  • 26
  • 34
6

A service may have multiple endpoints within a single host, but every endpoint must have a unique combination of address, binding and contract. For an IIS-hosted service (that is, an .SVC file), just set the address of the endpoint to a relative URI and make sure that your Visual Studio or wsdl.exe generated client specifies the endpoint's name in its constructor.

See also the MSDN article Multiple Endpoints.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mark Cidade
  • 98,437
  • 31
  • 224
  • 236
0

You will need to create an entire new host if you are currently using IIS as your host - IIS only supports HTTP and not TCP bindings. If however you are using WAS or a windows service, then you'll be able to get away with simply creating a new net.tcp endpoint.

Bermo
  • 4,921
  • 1
  • 28
  • 31
0

We can use multiple endpoints for the same service. We can configure the web config in the following way also

 <service name="MessagePatternDemo.Service1">  
 <endpoint name="ep1" address="/ep1" binding="basicHttpBinding" 
   contract="MessagePatternDemo.IService1"/>  
 <endpoint name="ep2" address="/ep2" binding="wsHttpBinding"  
   contract="MessagePatternDemo.IService1" />  
 <endpoint name="mex" contract="IMetadataExchange" address="mex"  
   binding="mexHttpBinding" />  
 </service>   
Vinoth
  • 851
  • 7
  • 23