1
votes

Based on the documentation available at https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-wcf

Does a Stateful Service in WCF supports Sessions?

Tried the below attributes but it does not work.

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]

public class CalculatorService : ICalculator

[ServiceContract(SessionMode=SessionMode.Required)]

public interface ICalculator


Any changes I need to do WCFCommunicationListener to support sessions?

protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
    {
        return new[]
        {
            new ServiceReplicaListener( (context) =>
                new WcfCommunicationListener<ICalculator>(context, new CalculatorService(),WcfUtility.CreateTcpListenerBinding(),"WCFServiceEndpoint")
            )
       }; 
    }
1

1 Answers

0
votes

I could able to achieve sessions in WCF Stateful Service using the following code.

protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
    {
        return new[]
        {
            new ServiceReplicaListener( (context) =>
             {
                var wcfCommunicationListener = new WcfCommunicationListener<ICalculator>(context, new CalculatorService(),WcfUtility.CreateTcpListenerBinding(),"WCFServiceEndpoint");                                        
                wcfCommunicationListener.ServiceHost.Description.Behaviors.Remove(typeof(ServiceBehaviorAttribute));
                wcfCommunicationListener.ServiceHost.Description.Behaviors.Add(new ServiceBehaviorAttribute() { InstanceContextMode = InstanceContextMode.PerSession});                    
                return wcfCommunicationListener;
             }   
            )
       }; 
    }