
Configuring a Service to Use Multiple Endpoints
Recall that a host can expose a single WCF service from multiple endpoints. This can be ideal when you wish
to allow the client to connect in the most appropriate manner. For example, outwardly facing callers could
opt for an HTTP-based binding. In-house callers could opt for a TCP binding to bypass the performance
issues found with HTTP / XML / SOAP.
To expose multiple endpoints, update the correct <service> section of your *.config file. Each endpoint
should be given a friendly string moniker using the name attribute. Consider the following update to the
previous *.config file. When the ServiceHost object is created, it will automatically create an endpoint for
each binding.
<?xml version = "1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name = "WcfMathService.MyCalc">
<!-- HTTP binding on port 8080. -->
<endpoint name = "WcfMathServiceHttpEndpoint"
address ="http://localhost:8080/MyCalc"
binding = "wsHttpBinding"
contract = "WcfMathService.IBasicMath"/>
<!-- TCP binding on port 8090. -->
<endpoint name = "WcfMathServiceTcpEndpoint"
address ="net.tcp://localhost:8090/MyCalc"
binding = "netTcpBinding"
contract = "WcfMathService.IBasicMath"/>
</service>
</services>
</system.serviceModel>
</configuration>
Once you refresh (or initially create) the client proxy, the client’s *.config file will now present both
endpoints.
You can specify the name of the <endpoint> as a constructor argument to the proxy.
Specifying the Host ABCs in Code
Table of Contents
Copyright (c) 2008. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an
online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.
Courseware
Training Resources
Tutorials
Services