ReliableSessionOverHttps サンプルは、Reliable Sessions での SSL トランスポート セキュリティの使用を示しています。 Reliable Sessions は、WS-Reliable メッセージング プロトコルを実装します。 信頼できるセッションを介して WS-Security を作成することで、セキュリティで保護された信頼できるセッションを作成できます。 ただし、代わりに SSL で HTTP トランスポート セキュリティを使用することもできます。
サンプルの詳細
SSL を使用すると、パケット自体がセキュリティで保護されます。 これは、WS-Secure Conversation を使用して信頼できるセッションをセキュリティで保護するのとは異なる点に注意してください。
HTTPS 経由で信頼できるセッションを使用するには、カスタム バインドを作成する必要があります。 このサンプルは、電卓サービスを実装する 作業の開始 に基づいています。 カスタム バインドは、信頼できるセッション バインド要素と <httpsTransport> を使用して作成されます。 カスタム バインドの構成を次に示します。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service
name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<!-- use base address provided by host -->
<endpoint address=""
binding="customBinding"
bindingConfiguration="reliableSessionOverHttps"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<!-- the mex endpoint is exposed as http://localhost/servicemodelsamples/service.svc/mex-->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<customBinding>
<binding name="reliableSessionOverHttps">
<reliableSession />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
サンプルのプログラム コードは、 作業の開始 サービスと同じです。 サンプルをビルドして実行する前に、Web サーバー証明書ウィザードを使用して証明書を作成して割り当てる必要があります。 構成ファイル設定のエンドポイント定義とバインド定義を使用すると、クライアントの次のサンプル構成に示すように、カスタム バインドを使用できます。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<!-- this endpoint has an https: address -->
<endpoint name=""
address="https://localhost/servicemodelsamples/service.svc"
binding="customBinding"
bindingConfiguration="reliableSessionOverHttps"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
</client>
<bindings>
<customBinding>
<binding name="reliableSessionOverHttps">
<reliableSession />
<httpsTransport />
</binding>
</customBinding>
</bindings>
</system.serviceModel>
</configuration>
指定されたアドレスは、 https://
スキームを使用します。
このサンプルで使用する証明書は、Makecert.exeで作成されたテスト証明書であるため、ブラウザーから https: アドレス ( https://localhost/servicemodelsamples/service.svc
など) にアクセスしようとすると、セキュリティ アラートが表示されます。 Windows Communication Foundation (WCF) クライアントがテスト証明書を使用できるようにするために、セキュリティ アラートを抑制するためのコードがいくつかクライアントに追加されました。 運用環境の証明書を使用する場合、このコードと付随するクラスは必要ありません。
// This code is required only for test certificates like those created by Makecert.exe.
PermissiveCertificatePolicy.Enact("CN=ServiceModelSamples-HTTPS-Server");
サンプルを実行すると、操作要求と応答がクライアント コンソール ウィンドウに表示されます。 クライアント ウィンドウで Enter キーを押して、クライアントをシャットダウンします。
Add(100,15.99) = 115.99
Subtract(145,76.54) = 68.46
Multiply(9,81.25) = 731.25
Divide(22,7) = 3.14285714285714
Press <ENTER> to terminate client.
サンプルを設定、ビルド、実行するには
次のコマンド ASP.NET 使用して 4.0 をインストールします。
%windir%\Microsoft.NET\Framework\v4.0.XXXXX\aspnet_regiis.exe /i /enable
Windows Communication Foundation サンプル のOne-Time セットアップ手順を実行していることを確認します。
インターネット インフォメーション サービス (IIS) サーバー証明書のインストール手順を実行していることを確認します。
ソリューションの C# または Visual Basic .NET エディションをビルドするには、「Windows Communication Foundation サンプルのビルド」の手順に従います。
単一または複数のコンピューター間の構成でサンプルを実行するには、「Windows Communication Foundation Samplesの実行」の手順に従います。