共用方式為


Windows 驗證的傳輸安全性

下列狀況顯示使用 Windows 安全性加以保障的 Windows Communication Foundation (WCF) 用戶端與服務。如需 如需 程式設計的詳細資訊,請參閱 HOW TO:使用 Windows 認證來確保服務安全

內部網路 Web 服務顯示人力資源資訊。用戶端為 Windows Form 應用程式。應用程式部署於由 Kerberos 控制站負責網域安全的網域內。

Windows 驗證的傳輸安全性

特性 描述

安全性模式

傳輸

互通性

僅限 WCF

驗證 (伺服器)

驗證 (用戶端)

是 (使用 Windows 整合式驗證)

是 (使用 Windows 整合式驗證)

完整性

機密性

傳輸

NET.TCP

繫結

NetTcpBinding

服務

下列程式碼和組態要獨立執行。執行下列任一步驟:

  • 使用不含組態的程式碼建立獨立服務。
  • 使用提供的組態建立服務,但不要定義任何端點。

程式碼

下列程式碼顯示如何建立使用 Windows 安全性的服務端點。

組態

可使用以下組態來取代程式碼設定服務端點。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <behaviors />
    <services>
      <service behaviorConfiguration="" name="ServiceModel.Calculator">
        <endpoint address="net.tcp://localhost:8008/Calculator" 
                  binding="netTcpBinding"
          bindingConfiguration="WindowsClientOverTcp" 
                  name="WindowsClientOverTcp"
                  contract="ServiceModel.ICalculator" />
      </service>
    </services>
    <bindings>
      <netTcpBinding>
        <binding name="WindowsClientOverTcp">
          <security mode="Transport">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client />
  </system.serviceModel>
</configuration>

用戶端

下列程式碼和組態要獨立執行。執行下列其中一項:

  • 使用此程式碼 (和用戶端程式碼) 建立獨立用戶端。
  • 建立未定義任何端點位址的用戶端,然後改用可接受組態名稱當做引數的用戶端建構函式。例如:

程式碼

下列程式碼會建立用戶端。繫結會設定為使用傳輸模式安全性,採用 TCP 傳輸,並將用戶端認證類型設為 Windows。

組態

可使用以下組態來取代程式碼建立用戶端。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_ICalculator" >
          <security mode="Transport">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:8008/Calculator" 
                binding="netTcpBinding"          
                bindingConfiguration="NetTcpBinding_ICalculator" 
                contract="ICalculator"
                name="NetTcpBinding_ICalculator">
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

請參閱

工作

HOW TO:使用 Windows 認證來確保服務安全

概念

安全性概觀