0

I can't get my values stored in the WCF session when use WS2007FederationHttpBinding. I've seen this topic Session in WCF not consistent, but it didn't help. Moreover, I don't care about reliable session, I just want to store some info in the session and read it at the second request. This scheme works for me with basicHttpsBinding.

Here is my binding. After channel creation I store it to the client Session

 var binding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.TransportWithMessageCredential);
 binding.Security.Message.EstablishSecurityContext = true;
 binding.Security.Message.IssuedKeyType = SecurityKeyType.BearerKey;
 binding.MaxReceivedMessageSize = 4000000;
 var serviceFactory = new ChannelFactory<T>(binding, new EndpointAddress(serviceUrl));
 serviceFactory.Credentials.SupportInteractive = false;
 var channel = serviceFactory.CreateChannelWithIssuedToken(token);

Service configuration: <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

Session access in the service:

HttpContext.Current.Session["serviceSession"] = "123";

Session retrieval in the service (is always null on the second request but SessionId is the same):

if (HttpContext.Current.Session["serviceSession"] == null) ...

I keep the channel itself in the client session between two requests and reuse it taking from the session for the second request.

Session["clientSession"] = channel;
Community
  • 1
  • 1
Lanayx
  • 2,731
  • 1
  • 23
  • 35

1 Answers1

0

I beleive HttpContext.Current.Session will only work if you configre asp comptability mode on the service. But even then it will not be correlated with your federation setting. What worked for me is to define the service instance mode as per session:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] 
public class Service : IService

and then you can use local data members of the service class to persist data between different calls of the same session.

Yaron Naveh
  • 23,560
  • 32
  • 103
  • 158