我在以下链接中遇到了描述和解决的问题
...但是我无法使用推荐的解决方案(使用客户端 HTTP 堆栈),因为我使用的是 JavaScript 而不是 Silverlight!
POST /PollingWcfServices/ServiceWcf.svc HTTP/1.1
Accept: */*
Content-Length: 564
Content-Type: application/soap+xml; charset=utf-8
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0
Host: foo
Connection: Keep-Alive
Pragma: no-cache
Cookie: ASP.NET_SessionId=iyr4sf55rm1kypafjdvlhm55
使用了下面的轮询代码
request.onreadystatechange = function () {
if (request.readyState == 4) {
if (request.status == 200)
//Process and Poll again
else
//Handle errors
}
request.open("POST", url);
request.setRequestHeader("Content-Type", "application/soap+xml;charset=utf-8");
request.send(httpBody);
不幸的是,由于 Session 是在 cookie 中设置的,服务器将尝试按顺序处理相同的 session 服务调用。这是长轮询过程的一个大问题。一个简单的解决方案是从 header 中删除 Cookie,使其看起来像使用 silverlight 客户端堆栈的 Silverlight 轮询。
request.setRequestHeader,只会附加到header值;这似乎没有任何区别,因为 cookie 似乎设置在 .send 的头部。
Mozilla 唯一的解决方案,位于
http://www.michael-noll.com/tutorials/cookie-monster-for-xmlhttprequest/
request.channel.loadFlags |= Ci.nsIRequest.LOAD_ANONYMOUS;
也不会删除 ASP.NET_SessionID cookie。尽管它确实删除了 ASPXAUTH cookie。
在启用 ASP.NET 兼容性/ session 的环境中,是否有人有解决方案来解决 AJAX 可访问的长时间运行的服务任务,而不会阻止后续的 AJAX 服务请求?
最佳答案
答案在这里...
In .NET 4, you can do this in Application_BeginRequest
if (Context.Request.Path.EndsWith("xxx.svc")) Context.SetSessionStateBehavior(SessionStateBehavior.ReadOnly);
-- How to force an IIS hosted WCF or ASMX [webservice] to use session object readonly?
通过更改回调服务的 SessionStateBehavior,我能够将此服务隔离为非顺序运行并停止阻塞。
关于javascript - AJAX 可访问的长时间运行的服务任务在启用 ASP.NET 兼容性/ session 的环境中阻止后续的 AJAX 服务请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10742211/