首页 文章

WCF通过TCP托管多个 endpoints

提问于
浏览
0

我有问题在WCF上托管多个 endpoints ,它给了我错误:

System.ServiceModel.AddressAlreadyInUseException:IP endpoints 0.0.0.0:808上已有一个侦听器 . 如果有另一个应用程序已在此 endpoints 上侦听,或者如果服务主机中有多个服务 endpoints 具有相同的IP endpoints 但具有不兼容的绑定配置,则可能会发生这种情况 . ---> System.Net.Sockets.SocketException: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

3 回答

  • 2

    看来问题出在您的MEX endpoints 上 - 它们在两个服务之间是相同的 . 尝试给他们不同的地址,看看这是否解决了问题 .

  • 0

    我的第一个猜测是你有另一个应用程序,侦听某个端口尝试将端口更改为这样的尝试在两个端口上尝试不同的端口

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

    如果成功,请尝试使用此命令列出所有应用程序和侦听端口

    netstat -an
    
  • 0

    在我的情况下,我已更新.net框架,我收到此错误 . 我通过删除配置文件中的listenBacklog和maxConnections属性来解决此错误

    Here是解决我的问题的解决方案 .

相关问题