調試 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).
異常提示綁定不匹配,常見原因:
本案例中,服務端未啟用安全,而路由服務的客戶端綁定採用預設 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 通訊雙端的綁定屬性(安全、編碼、交易、可靠會話等)必須完全一致。建議採用「配置共享」或「集中管理綁定配置」策略,避免手工維護導致差異。