ReliableSession サンプルは、さまざまなトランスポートおよびメッセージ エンコード要素を使用してカスタム バインドを構成する方法を示しています。特に、信頼性の高いセッションを有効にします。 カスタム バインドは、個別のバインド要素の順序付きリストによって定義されます。
サンプルの詳細
信頼できるセッションは、信頼性の高いメッセージングとセッションの機能を提供します。 信頼できるメッセージングは、障害発生時に通信を再試行し、メッセージの順番の到着などの配信保証を指定できるようにします。 セッションは、呼び出し間でクライアントの状態を維持します。 このサンプルでは、クライアントの状態を維持するためのセッションを実装し、インオーダー配信保証を指定します。 このサンプルは、電卓サービスを実装する 作業の開始 に基づいています。 信頼できるセッション機能は、クライアントとサービスのアプリケーション構成ファイルで有効にされ、構成されます。
注
このサンプルのセットアップ手順とビルド手順は、このトピックの最後にあります。
バインド要素の順序は、チャネル スタック内のレイヤーを表すカスタム バインドを定義する上で重要です ( カスタム バインドを参照)。
サンプルのサービス構成は、次のコード例に示すように定義されています。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service
name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<!-- This endpoint is exposed at the base address provided by host: http://localhost/servicemodelsamples/service.svc -->
<!-- specify customBinding binding and a binding configuration to use -->
<endpoint address=""
binding="customBinding"
bindingConfiguration="Binding1"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<!-- The mex endpoint is exposed at http://localhost/servicemodelsamples/service.svc/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<!-- custom binding configuration - configures HTTP transport, reliable sessions -->
<bindings>
<customBinding>
<binding name="Binding1">
<reliableSession />
<security authenticationMode="SecureConversation"
requireSecurityContextCancellation="true">
</security>
<compositeDuplex />
<oneWay />
<textMessageEncoding messageVersion="Soap12WSAddressing10" writeEncoding="utf-8" />
<httpTransport authenticationScheme="Anonymous" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
proxyAuthenticationScheme="Anonymous" realm=""
useDefaultWebProxy="true" />
</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>
マシン間のシナリオで実行する場合は、サービスのホスト名を反映するようにクライアントのエンドポイント アドレスを変更する必要があります。
サンプルを実行すると、操作要求と応答がクライアント コンソール ウィンドウに表示されます。 クライアント ウィンドウで 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 セットアップ手順を実行していることを確認します。
ソリューションの C# または Visual Basic .NET エディションをビルドするには、「Windows Communication Foundation サンプルのビルド」の手順に従います。
単一または複数のコンピューター間の構成でサンプルを実行するには、「Windows Communication Foundation Samplesの実行」の手順に従います。
Von Bedeutung
クロスマシン構成でクライアントを実行する場合は、次の例に示すように、<endpoint> 要素の
address
属性と<compositeDuplex>のclientBaseAddress
属性の両方の "localhost" を適切なマシンの名前に置き換えてください。<endpoint name = "" address="http://service_machine_name/servicemodelsamples/service.svc" /> <compositeDuplex clientBaseAddress="http://client_machine_name:8000/myClient/" />