2012-01-06 132 views
3

我對已部署到IIS的服務有以下配置。我可以使用wsHttpBinding端點的URL添加服務的服務引用,但我無法使用URL將其添加到mexHttpBinding端點(並且我想切換客戶端以使用netTcpBinding)無法使用IIS中託管的netTcpBinding添加WCF服務的服務引用

我得到的錯誤是:

下載'http:// ServerName:98/MyService.svc/mex'時出錯。

請求失敗,HTTP狀態400:錯誤的請求。

元數據包含無法解析的引用:'http:// ServerName:98/MyService.svc/mex'。

元數據包含無法解析的引用:'http:// ServerName:98/MyService.svc/mex'。

<system.web> 
    <compilation debug="true" 
       targetFramework="4.0" /> 
    <customErrors mode="Off"/> 
</system.web> 

<system.serviceModel> 
    <bindings> 
    <netTcpBinding> 
     <binding name="netTcpBinding_MyService" /> 
    </netTcpBinding> 
    <wsHttpBinding> 
     <binding name="wsHttpBinding_MyService" 
       maxBufferPoolSize="2147483647" 
       maxReceivedMessageSize="2147483647" /> 
    </wsHttpBinding> 
    </bindings> 
    <services> 
    <service behaviorConfiguration="ServiceBehaviour" 
      name="MyService.MyService"> 
     <endpoint address="" 
       binding="wsHttpBinding" 
       bindingConfiguration="wsHttpBinding_MyService" 
       name="MyServiceEndpoint" 
       contract="MyService.IMyService" /> 
     <endpoint address="net.tcp://ServerName:198/MyService.svc" 
       binding="netTcpBinding" 
       bindingConfiguration="netTcpBinding_MyService" 
       name="MyServiceNetTcpEndpoint" 
       contract="MyService.IMyService" /> 
     <endpoint address="http://ServerName:98/MyService.svc/mex" 
       binding="mexHttpBinding" 
       contract="IMetadataExchange" /> 
     <host> 
     <baseAddresses> 
      <add baseAddress="http://ServerName:98/" /> 
      <add baseAddress="net.tcp://ServerName:198/" /> 
     </baseAddresses> 
     </host> 
    </service> 
    </services> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior name="ServiceBehaviour"> 
     <serviceMetadata httpGetEnabled="true" 
         policyVersion="Policy15" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
     <serviceCredentials> 
      <windowsAuthentication includeWindowsGroups="true" 
           allowAnonymousLogons="false" /> 
     </serviceCredentials> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
</system.webServer> 

最奇怪的是,這個配置是從我配置的其他服務複製幾乎原封不動和部署,我是能夠服務引用成功添加使用mexHttpBinding端點客戶端。對於原來的服務配置是這樣的:

<system.web> 
    <compilation debug="true" 
       targetFramework="4.0" /> 
    <customErrors mode="Off"/> 
    </system.web> 

    <system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="netTcpBinding_MyOtherService" /> 
     </netTcpBinding> 
     <wsHttpBinding> 
     <binding name="wsHttpBinding_MyOtherService" 
       maxBufferPoolSize="2147483647" 
       maxReceivedMessageSize="2147483647" /> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="ServiceBehaviour" 
       name="MyOtherService.MyOtherService"> 
     <endpoint address="" 
        binding="wsHttpBinding" 
        bindingConfiguration="wsHttpBinding_MyOtherService" 
        name="MyOtherServiceEndpoint" 
        contract="MyOtherService.IMyOtherService" /> 
     <endpoint address="" 
        binding="netTcpBinding" 
        bindingConfiguration="netTcpBinding_MyOtherService" 
        name="MyOtherServiceNetTcpEndpoint" 
        contract="MyOtherService.IMyOtherService" /> 
     <endpoint address="mex" 
        binding="mexHttpBinding" 
        bindingConfiguration="" 
        name="MyOtherServiceMexHttpBindingEndpoint" 
        contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://ServerName:97/" /> 
      <add baseAddress="net.tcp://ServerName:970/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceBehaviour"> 
      <serviceMetadata httpGetEnabled="true" 
          policyVersion="Policy15" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <serviceCredentials> 
      <windowsAuthentication includeWindowsGroups="true" 
            allowAnonymousLogons="false" /> 
      </serviceCredentials> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

正如你會發現,在主機的唯一相關的差異對於NetTcpBinding的端點和mexHttpBinding端點地址。最初,我開始與他們都是空的,但正如我一直在試圖讓它的工作,我添加了明確的地址英寸

而且,兩個服務配置相同的IIS,即net.tcp綁定在相關端口上啓用和配置。它們也都在同一臺服務器上運行不同的站點和獨立的應用程序池(並且這兩個應用程序池都以相同的身份運行)。

任何幫助,將不勝感激,謝謝。

回答

2

解決了它。對於我們部署的每個環境,我們都有一個Web。{Environment} .config,並且在構建時沒有通過Web.config複製正確的配置,因爲Web.config上存在文件鎖定(可能未檢出TFS) ...

其中一件事我應該先檢查一下,但是當它以前一直在工作,然後在沒有警告的情況下突然爆發,我從來沒有想過要檢查。

1

在IIS中使用服務時,無法在端點配置中設置絕對URL。根URL由IIS控制,它遵循Web站點(指定端口)/ Web應用程序/虛擬目錄/ SvcFile的通用結構。您只能指定.svc文件後指定的地址的相對部分。

設置完全絕對地址和基地址僅適用於自託管方案。

即使使用wsHttpBinding端點添加服務引用,您仍然應該能夠將其切換到netTcpBinding端點,因爲該端點應該在您的WSDL中進行描述(如果您刪除了這些絕對地址)。兩個端點都應該在客戶端的配置文件中進行配置。然後,您只需將端點配置的名稱傳遞給服務存根(WCF代理)的構造函數即可。

+0

正如我所說,我最初開始時沒有netTcpBinding的地址,只是「mex」作爲mexHttpBinding的地址,並沒有工作。這是我在其他服務中使用的配置。 – alimbada 2012-01-09 09:58:55

相關問題