user726720
user726720

Reputation: 1247

Multiple endpoints in wcf

I'm trying to do multiple endpoints for a single WCF Service, so that each endpoint has its separate interface / methods. I'm using TCP

app.config:

<configuration>
  ....
  <system.serviceModel>
    <services>
      <service name="WCFLibrary.CalculatorService">
          <host>
            <baseAddresses>
              <!--<add baseAddress="http://localhost:8788/CalculatorService/" />-->
              <add baseAddress="net.tcp://localhost:8523/CalculatorService" />
            </baseAddresses>
          </host>
          <endpoint name="ServiceTCPEndPoint" 
              address="" 
              binding="netTcpBinding" 
              contract="WCFLibrary.ICalculator">
            <identity>
              <dns value="localhost" />
            </identity>
          </endpoint>
          <endpoint name="ServiceMexEndPoint" address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
      </service>
      <service name ="WCFLibrary.MyWorldService">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8524/MyWorldService"/>
          </baseAddresses>
        </host>
        <endpoint name="HelloWorldTCPEndpoint" 
            address="" 
            binding="netTcpBinding" 
            contract="WCFLibrary.MyWorld">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint name="HelloWorldMexEndPoint" 
            address="mex" 
            binding="mexTcpBinding" 
            contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata/>
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

My first endpoint is working, but my second endpoint doesn't work. What could be wrong here. Secondly why can't we browse tcp, like we can do for HTTP. I know we can test tcp using svcutil. Is there anyway to browse TCP.

EDIT:

WCF:

http://pastebin.com/gHHRKeYZ

WindowsService:

http://pastebin.com/kjM3iRYj

Upvotes: 1

Views: 1164

Answers (2)

pposada
pposada

Reputation: 178

If you are using @Staish configuration, you can try to uncomment this line in the service behaviour.

 <!--<serviceMetadata httpGetEnabled="**True**" httpsGetEnabled="False" />-->

Then you'll be able to use the svcutil to create the proxy.

You can comment it back before publishing if you want.

Upvotes: 1

Satish
Satish

Reputation: 3100

All net.tcp endpoints should use the same port using port sharing.

There are several articles/tutorials in MSDN and else where on how to achieve this. Here is one

Try this config settings

<system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="tcpDefault" portSharingEnabled="true" />

  </netTcpBinding>
</bindings>
<services>
  <service name="WCFLibrary.CalculatorService">

      <host>
        <baseAddresses>
          <!--<add baseAddress="http://localhost:8788/CalculatorService/" />-->
          <add baseAddress="net.tcp://localhost:8523/CalculatorService" />
        </baseAddresses>
      </host>
      <!-- Service Endpoints -->
      <!-- Unless fully qualified, aBddress is relative to base address supplied above -->
      <endpoint name="ServiceTCPEndPoint" address="" binding="netTcpBinding" bindingConfiguration="tcpDefault" contract="WCFLibrary.ICalculator">
        <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <!-- Metadata Endpoints -->
      <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
      <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
      <endpoint name="ServiceMexEndPoint" address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
    </service>
  <service name ="WCFLibrary.MyWorldService">
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8523/MyWorldService"/>
      </baseAddresses>
    </host>
    <endpoint name="HelloWorldTCPEndpoint" address="" binding="netTcpBinding"  bindingConfiguration="tcpDefault" contract="WCFLibrary.MyWorld">
      <identity>
        <dns value="localhost" />
      </identity>

    </endpoint>
    <endpoint name="HelloWorldMexEndPoint" address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, 
      set the values below to false before deployment -->
      <!--<serviceMetadata httpGetEnabled="False" httpsGetEnabled="False" />-->
      <serviceMetadata/>
      <!-- To receive exception details in faults for debugging purposes, 
      set the value below to true.  Set to false before deployment 
      to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Upvotes: 2

Related Questions