user726720
user726720

Reputation: 1237

WCF hosting mutiple endpoints with TCP

I'm having issue's hosting multiple endpoints on WCF, it's giving me error:

System.ServiceModel.AddressAlreadyInUseException: There is already a listener on IP endpoint 0.0.0.0:808. This could happen if there is another application already listening on this endpoint or if you have multiple service endpoints in your service host with the same IP endpoint but with incompatible binding configurations. ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted at system.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)

My App.config

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
        <add key="ClientSettingsProvider.ServiceUri" value="" />
      </appSettings>
      <system.web>
        <compilation debug="true" />
        <membership defaultProvider="ClientAuthenticationMembershipProvider">
          <providers>
            <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
          </providers>
        </membership>
        <roleManager defaultProvider="ClientRoleProvider" enabled="true">
          <providers>
            <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
          </providers>
        </roleManager>
      </system.web>

      <system.serviceModel>
        <diagnostics wmiProviderEnabled="true">
          <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
        </diagnostics>

        <bindings>
          <netTcpBinding>
            <binding name="TCPDefault" portSharingEnabled="true" />
          </netTcpBinding>
        </bindings>
        <services>
         <!--Service1-->
          <service name="WCFLibrary.CalculatorService" behaviorConfiguration="DebugBehavior">
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://localhost/CalculatorService" />

              </baseAddresses>
            </host>
            <endpoint address="" binding="netTcpBinding" bindingConfiguration="TCPDefault"
              name="ServiceTCPEndPoint" contract="WCFLibrary.ICalculator">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
           <endpoint address="mex" binding="mexTcpBinding" name="ServiceMexEndPoint"
              contract="IMetadataExchange" />
         </service>
         <!--Service2-->
          <service name="WCFLibrary.MyWorldService" behaviorConfiguration="DebugBehavior">
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://localhost/MyWorldService" />

              </baseAddresses>          
            </host>
            <endpoint address="" binding="netTcpBinding" bindingConfiguration="TCPDefault"
          name="WCFLibrary.MyWorldService" contract="WCFLibrary.IMyWorld">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexTcpBinding" name="ServiceMexEndPoint"
               contract="IMetadataExchange" />          
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="DebugBehavior">

              <serviceMetadata/>

              <serviceDebug includeExceptionDetailInFaults="True" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>

I'm having separate services with callbacks. Please advise.

**Modified App.config**

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <diagnostics wmiProviderEnabled="true">
      <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
    </diagnostics>

    <bindings>
      <netTcpBinding>
        <binding name="TCPDefault" portSharingEnabled="true" />
      </netTcpBinding>
    </bindings>
    <services>
     <!--Service1-->
      <service name="WCFLibrary.CalculatorService" behaviorConfiguration="DebugBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost/CalculatorService" />

          </baseAddresses>
        </host>
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="TCPDefault"
          name="ServiceTCPEndPoint" contract="WCFLibrary.ICalculator">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
       <endpoint address="net.tcp://localhost:8002/CalculatorService/mex" binding="mexTcpBinding" name="ServiceMexEndPoint"
          contract="IMetadataExchange" />
     </service>
     <!--Service2-->
      <service name="WCFLibrary.MyWorldService" behaviorConfiguration="DebugBehavior">
        <host>
          <baseAddresses>
            <!--<add baseAddress="net.tcp://localhost/MyWorldService" />-->

          </baseAddresses>          
        </host>
        <endpoint address="net.tcp://localhost/MyWorldService" binding="netTcpBinding" bindingConfiguration="TCPDefault"
      name="WCFLibrary.MyWorldService" contract="WCFLibrary.IMyWorld">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="net.tcp://localhost:8001/MyWorldService/mex" binding="mexTcpBinding" name="ServiceMexEndPoint"
           contract="IMetadataExchange" />          
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="DebugBehavior">
          <!-- 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>
  </system.serviceModel>
</configuration>

WCF:

http://pastebin.com/gHHRKeYZ

WindowsService:

http://pastebin.com/kjM3iRYj

Upvotes: 0

Views: 2786

Answers (3)

Nawaz Khan
Nawaz Khan

Reputation: 17

In my case, I have update the .net framework and i receive this error. I resolve this error by removing the listenBacklog and maxConnections attributes of in configuration file

Here is the solution which resolve my problem.

Upvotes: 0

BRAHIM Kamel
BRAHIM Kamel

Reputation: 13765

My first guess is that you have another application that listen on the some port try to change the port to something like this try a different port on both

  <add baseAddress="net.tcp://localhost:2200/CalculatorService" />
 <add baseAddress="net.tcp://localhost/MyWorldService:2200" />

if this succeed try to list all apps and listening port using this command

netstat -an 

Upvotes: 0

The other other Alan
The other other Alan

Reputation: 1908

It appears the problem is with your MEX endpoints - they are identical between the two services. Try giving them different addresses to see if this resolves the problem.

Upvotes: 2

Related Questions