[WCF] 停用 wsHttpBinding 的安全認證及加密機制

摘要:[WCF] 停用 wsHttpBinding 的安全認證及加密機制

使用 Visual Studio 建立 WCF 程式時,預設有安全認證機制,本機測試時因為 Service 與 Client 同一個方案不會發生認證問題,當 Service 放在不同電腦或網域會造成 Cleint 無法連上;如果不使用安全認證,可以分別在 Client 與 Server 的組態檔停用安全機制。

在 Website 的 web.config 設定 security mode="None"


<bindings>     
  <wsHttpBinding>       
    <binding name="myBindingConfiguration"
             openTimeout="00:10:00"
             closeTimeout="00:10:00"
             sendTimeout="00:10:00"
             receiveTimeout="00:10:00"
             maxBufferPoolSize="16776960"
             maxReceivedMessageSize="16776960">
      <security mode="None"></security><!-- 修改這行 -->
    </binding>
  </wsHttpBinding>
</bindings>

 

在 WinForm 的 app.config 設定 security mode="None"


<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_IServiceCommon" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="524288" maxReceivedMessageSize="6553600" messageEncoding="Text"
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="819200" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="None"> <!-- 修改這行 -->
        <transport clientCredentialType="Windows" proxyCredentialType="None"
            realm="">
          <extendedProtectionPolicy policyEnforcement="Never" />
        </transport>
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
            algorithmSuite="Default" establishSecurityContext="true" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

參考:【茶包射手專欄】跨機器之WCF認證問題