首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> 關於.NET

WCF 分散式開發常見錯誤 (28):請求的升級不受支援

     編輯:關於.NET

錯誤現象

調試 WCF 4.0 Routing 服務時,客戶端拋出:

The requested upgrade is not supported by 'net.tcp://localhost:9002/WCFServiceB'. This could be due to mismatched bindings (for example security enabled on the client and not on the server).

環境

  • OS: Windows XP Professional
  • IDE: Visual Studio 2010 Beta2
  • Framework: .NET Framework 4.0

根因分析

異常提示綁定不匹配,常見原因:

  1. 客戶端與服務端安全模式不一致(如客戶端啟用傳輸安全,服務端關閉)。
  2. 編碼方式不同(Text/Binary/MTOM)。
  3. SOAP 版本不同(1.1 vs 1.2)。
  4. 交易流設定不一致。

本案例中,服務端未啟用安全,而路由服務的客戶端綁定採用預設 netTcpBinding(預設開啟傳輸安全),導致不匹配。

解決方案:統一客戶端綁定配置

在客戶端 <system.serviceModel> 顯式定義無安全的 netTcpBinding 配置:

<system.serviceModel>
  <client>
    <endpoint name="EndPointB"
              address="net.tcp://localhost:9002/WCFServiceB"
              binding="netTcpBinding"
              bindingConfiguration="netTcpConfig"
              contract="*" />
  </client>
  <bindings>
    <netTcpBinding>
      <binding name="netTcpConfig">
        <security mode="None" />
      </binding>
    </netTcpBinding>
  </bindings>
</system.serviceModel>

核心原則

WCF 通訊雙端的綁定屬性(安全、編碼、交易、可靠會話等)必須完全一致。建議採用「配置共享」或「集中管理綁定配置」策略,避免手工維護導致差異。

參考資源

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved