2011-11-30 149 views
4

以下是我的WCF服務配置。我使用2 ServiceHost來託管2種服務類型。他們使用相同的基地址,但他們爲他們的端點使用不同的相對地址。WCF錯誤:URI的註冊已存在

但我得到這個錯誤,爲什麼?

服務無法啓動。 System.InvalidOperationException:具有合約「IHttpGetHelpPageAndMetadataContract」的'http:// earth:1111 /'處的ChannelDispatcher無法打開其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> 

有些更離譜的結論:

我改變了我的配置是:

<?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> 

然後我發現我可以在Visual Studio中使用「添加服務引用」與以下地址:

+0

似乎WCF端點有一些令人困惑的設計。 – smwikipedia

回答

0

你有沒有試圖消除服務區塊之一,端點組合成一個?

我看不出有什麼理由讓你把它們分開。

確保baseaddress +端點地址是唯一的。

+0

實際上,baseaddress +端點地址現在是唯一的。 – smwikipedia

+0

我更新了我的帖子。 – smwikipedia

0

您無法使用相同的基地址託管兩項服務。

您需要在另一個端口或地址上託管另一個。

喜歡的東西

http://Earth:1111/Service1 

http://Earth:1111/Service2 
0

我真的不知道爲什麼是這樣的話,但一個解決方案是,沒有基址離開服務,並指定完整地址爲端點。這不會改變不同端點的地址,也不會改變地址唯一性。我無法在MSDN上找到任何相關的參考資料。

根據我自己的經驗,問題出現在http而不是net.tcp。我沒有使用服務元數據。我認爲「IHttpGetHelpPageAndMetadataContract」與元數據有關,但沒有辦法禁用它。

1

可以使用相同的基地址來託管多個服務。設置HttpHelpPageEnabledHttpsHelpPageEnabled屬性全部ServiceDebugBehavior s到false,那麼它應該工作。

Atention:默認情況下,總是即使沒有明確地規定,不管是主機的行爲的描述集合中註冊的ServiceDebugBehavior(我只用程序化CONFIGRATION和ServiceHost類,而不是通過XML配置嘗試過)。所以,你應該添加一個明確的ServiceDebugBehavior並設置提到的屬性。 IncludeExceptionDetailInFaults屬性可以是true