Compartilhar via


WS Reliable Session

Download sample

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. 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. Ensure that you have performed the One-Time Set Up Procedure for the Windows Communication Foundation Samples.

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

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

© 2007 Microsoft Corporation. All rights reserved.