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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With