WS Reliable Session

This sample demonstrates the use of reliable sessions. Reliable sessions provide support for reliable messaging and sessions. Reliable messaging retries communication on failure and allows delivery assurances to be specified, such as in-order arrival of messages. Sessions maintain state for clients between calls. The sample implements sessions for maintaining client state and specifies in-order delivery assurances.

Note

]The samples may already be installed on your machine. Check for the following (default) directory before continuing.

<InstallDrive>:\WF_WCF_Samples

If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.

<InstallDrive>:\WF_WCF_Samples\WCF\Basic\Binding\WS\wsReliableSession

This sample is based on the Getting Started Sample that implements a calculator service. The reliable session features are enabled and configured in the application configuration files for the client and service.

In this sample, the service is hosted in Internet Information Services (IIS) and the client is a console application (.exe).

Note

The setup procedure and build instructions for this sample are located at the end of this topic.

The sample uses the wsHttpBinding. The binding is specified in the configuration files for both the client and service. The binding type is specified in the endpoint element’s binding attribute as shown in the following sample configuration.

<endpoint address=""
          binding="wsHttpBinding"
          bindingConfiguration="Binding1" 
          contract="Microsoft.ServiceModel.Samples.ICalculator" />

The endpoint contains a bindingConfiguration attribute that references a binding configuration named "Binding1." The binding configuration enables reliable sessions by setting the enabled attribute of the reliableSession element to true. Delivery assurances for ordered sessions are controlled by setting the ordered attribute to true or false. The default is true.

<bindings>
    <wsHttpBinding>
        <binding name="Binding1">
            <reliableSession enabled="true" />
        </binding>
    </wsHttpBinding>
</bindings>

The service implementation class implements PerSession instancing to maintain a separate class instance for each client, as shown in the following sample code.

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)] public class CalculatorService : ICalculator
{
    ...
}

When you run the sample, the operation requests and responses are displayed in the client console window. Press ENTER in the client window to shut down the client.

    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.

To set up, build, and run the sample

  1. Install ASP.NET 4.0 using the following command.

    %windir%\Microsoft.NET\Framework\v4.0.XXXXX\aspnet_regiis.exe /i /enable
    
  2. Ensure that you have performed the One-Time Setup Procedure for the Windows Communication Foundation Samples.

  3. To build the C# or Visual Basic .NET edition of the solution, follow the instructions in Building the Windows Communication Foundation Samples.

  4. To run the sample in a single- or cross-machine configuration, follow the instructions in Running the Windows Communication Foundation Samples.