WCF Service with Multiple Endpoints



Recently, I was asked whether a Windows Communication Foundation (WCF) service can have both net.tcp and http binding. I did a proof of concept (POC) work and want to share with you here.

How to

Actually, there is a good business/technical reasons behind creating services with multiple endpoints. For example, you may have a service that is consumed both your application and external clients. Now, you may use net.tcp binding for internal usage (performance reasons), and http binding for external usages (interoperability reasons).

To accomplish this, there are 3 major things you need to do:

  1. Define specific addresses for each endpoint within baseAddresses section.
  2. Name your service endpoints.
  3. Adjust client side configuration section accordingly after referenced.

If you ignore naming service endpoints, you will get the following error:

‘An endpoint configuration section for contract ‘…’ could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.’


For your convenience, service configuration displayed below:

      <service behaviorConfiguration="serviceBehavior" name="Demo1.ServiceHost.Self.Service1"> 
            <add baseAddress="http://localhost:8777/DesignTime/Demo1/Service1" />
            <add baseAddress ="net.tcp://localhost:8767/DesignTime/Demo1/Service1"/>
<endpoint address="withHttp" binding="basicHttpBinding" name="bHttpService1"
                   contract="Demo1.ServiceHost.Self.IService1" />
<endpoint address="withTcp" binding="netTcpBinding" name="tcpService1"
                   contract="Demo1.ServiceHost.Self.IService1" />
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexTcpBinding" name="mex" contract="IMetadataExchange" /> 
         <behavior name="serviceBehavior">
           <serviceThrottling maxConcurrentCalls="200" maxConcurrentInstances="2000" maxConcurrentSessions="2000"/>
           <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
           <serviceMetadata httpGetEnabled="true"/>
           <serviceDebug includeExceptionDetailInFaults="true"/>

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.