使用WS2007FederationHttpBinding时,我无法将我的值存储在 WCF会话中。我在 WCF 中看到过这个主题 Session not compatible,但它没有帮助。此外,我不关心可靠的会话,我只想在会话中存储一些信息并在第二个请求时读取它。这个方案适用于我的 basicHttpsBinding。
这是我的绑定。创建频道后,我将其存储到客户端 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);
服务配置:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
服务中的会话访问:
HttpContext.Current.Session["serviceSession"] = "123";
服务中的会话检索(在第二个请求中始终为空,但SessionId相同):
if (HttpContext.Current.Session["serviceSession"] == null) ...
我将通道本身保留在两个请求之间的客户端会话中,并将其从会话中重新用于第二个请求。
Session["clientSession"] = channel;