WCF 错误:URI 的注册已存在

smw*_*dia 5 wcf

以下是我的 WCF 服务配置。我使用 2 个ServiceHost 来托管 2 种服务类型。它们使用相同的基地址,但对其端点使用不同的相对地址。

但我收到这个错误,为什么?

服务无法启动。System.InvalidOperationException:“http://earth:1111/”处的 ChannelDispatcher 与合约““IHttpGetHelpPageAndMetadataContract””无法打开其 IChannelListener。---> System.InvalidOperationException: URI 'http://earth:1111/' 的注册已存在。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="serviceBehavior" name="Distributed.Troubleshooting.System.IIS.IISServiceType">
        <endpoint address="iis" binding="basicHttpBinding" name="iis"
          contract="Distributed.Troubleshooting.System.IIS.IISServiceContract" />
        <endpoint address="iismex" binding="mexHttpBinding" bindingConfiguration=""
          name="iismex" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://Earth:1111/" />
          </baseAddresses>
        </host>
      </service>
      <service behaviorConfiguration="serviceBehavior" name="Distributed.Troubleshooting.System.SQL.SQLServiceType">
        <endpoint address="sql" binding="basicHttpBinding" name="sql"
          contract="Distributed.Troubleshooting.System.SQL.SQLServiceContract" />
        <endpoint address="sqlmex" binding="mexHttpBinding" bindingConfiguration=""
          name="sqlmex" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://Earth:1111/" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

一些更荒谬的发现:

我将我的配置更改为:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="serviceBehavior" name="Distributed.Troubleshooting.System.IIS.IISServiceType">
        <endpoint address="http://Earth:1111/iis" binding="basicHttpBinding" name="iis"
          contract="Distributed.Troubleshooting.System.IIS.IISServiceContract" />
        <endpoint address="http://Earth:1111/iismex" binding="mexHttpBinding" bindingConfiguration=""
          name="iismex" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://Earth:1111/iis" />
          </baseAddresses>
        </host>
      </service>
      <service behaviorConfiguration="serviceBehavior" name="Distributed.Troubleshooting.System.SQL.SQLServiceType">
        <endpoint address="http://Earth:1111/sql" binding="basicHttpBinding" name="sql"
          contract="Distributed.Troubleshooting.System.SQL.SQLServiceContract" />
        <endpoint address="http://Earth:1111/sqlmex" binding="mexHttpBinding" bindingConfiguration=""
          name="sqlmex" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://Earth:1111/sql" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

然后我发现我可以在 Visual Studio 中使用“添加服务引用”,地址如下:

Wil*_*iam 0

您是否尝试过删除其中一个服务块并将端点合并为一个?

我看不出你有什么理由把他们分开。

确保基地址+端点地址是唯一的。