メッセージ セキュリティ Windows
このサンプルでは、Windows 認証によるメッセージ レベルのセキュリティを使用するよう WSHttpBinding バインディングを構成する方法を示します。このサンプルは、「入門サンプル」に基づいています。このサンプルでは、サービスはインターネット インフォメーション サービス (IIS) によってホストされており、クライアントはコンソール アプリケーション (.exe) です。
メモ : |
---|
このサンプルのセットアップ手順とビルド手順については、このトピックの最後を参照してください。 |
wsHttpBinding Elementの既定のセキュリティは、Windows 認証を使用するメッセージ セキュリティです。このサンプルの構成ファイルでは、security Element in wsHttpBinding の mode
属性を Message
に、clientCredentialType
属性を Windows
にそれぞれ明示的に設定します。これらの値はこのバインディングの既定値ですが、明示的に構成されています。これらの使用例を示すサンプル構成を次に示します。
<bindings>
<wsHttpBinding>
<binding name="Binding1">
<security mode="Message">
<message clientCredentialType="Windows"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
クライアント エンドポイント構成は、サービス エンドポイントの絶対アドレス、バインディング、およびコントラクトで構成されます。クライアント バインディングは、適切な securityMode
と authenticationMode
で構成されます。
<configuration>
<system.serviceModel>
<client>
<endpoint address=
"https://localhost/servicemodelsamples/service.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding1"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
</client>
<bindings>
<wsHttpBinding>
<!--
<!--The default security for the WSHttpBinding is-->
<!--Message security using Windows authentication. -->
<!--This configuration explicitly defines the security mode -->
<!--as Message and the clientCredentialType as Windows -->
<!--for demonstration purposes. -->
<binding name="Binding1">
<security mode="Message">
<message clientCredentialType="Windows"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
サービス ソース コードは、ServiceSecurityContext を使用して呼び出し元の ID へのアクセスを可能にする方法を示すように変更されています。
public string GetCallerIdentity()
{
// The Windows identity of the caller can be accessed on the ServiceSecurityContext.WindowsIdentity.
return OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;
}
このサンプルを実行する場合は、操作要求および応答はクライアントのコンソール ウィンドウに表示されます。最初に呼び出されるメソッド GetCallerIdentity
は、呼び出し元の ID の名前をクライアントに返します。クライアントをシャットダウンするには、コンソール ウィンドウで Enter キーを押します。
サンプルを設定、ビルド、および実行するには
「Windows Communication Foundation サンプルの 1 回限りのセットアップの手順」が実行済みであることを確認します。
ソリューションの C# 版または Visual Basic .NET 版をビルドするには、「Windows Communication Foundation サンプルのビルド」の手順に従います。
サンプルを単一コンピュータ構成または複数コンピュータ構成で実行するには、「Windows Communication Foundation サンプルの実行」の手順に従います。
Copyright © 2007 by Microsoft Corporation.All rights reserved.