我不能讓存儲在WCF 會議使用時WS2007FederationHttpBinding我的價值觀。我看過這個話題Session in WCF not consistent,但它沒有幫助。而且,我不關心可靠的會話,我只想在會話中存儲一些信息並在第二個請求中讀取它。這個方案適用於basicHttpsBinding。使用會話使用WCF WS2007FederationHttpBinding(WSFederationHttpBinding)
這是我的綁定。頻道創建後,我將其存儲到客戶端會話
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;