AJAX accessible long running service tasks blockin

2020-04-30 02:16发布

I'm having a problem described and solved at the following link

http://blogs.msdn.com/b/silverlightws/archive/2009/09/30/having-a-pollingduplex-service-and-any-other-wcf-service-in-the-same-website-causes-silverlight-calls-to-be-slow.aspx

... However I cannot use the recommended solution (Use Client HTTP stack) since I'm using JavaScript and not 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

The following polling code is used

  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);

Unfortunately since the Session is set in the cookie, the server will try and process same session service calls sequentially. This is a huge problem with the long poll process. A simple solution would be to remove the Cookie from the headers, to make it look like a Silverlight poll using the silverlight client stack.

request.setRequestHeader, will only append to the header value; this doesn't seem to make any difference since the cookie seems to be set in the head on .send.

The Mozilla only solution, found at

http://www.michael-noll.com/tutorials/cookie-monster-for-xmlhttprequest/

request.channel.loadFlags |= Ci.nsIRequest.LOAD_ANONYMOUS;

Doesn't sem to remove the ASP.NET_SessionID cookie either. Although it does remove the ASPXAUTH cookie.

Does anyone have a solution for AJAX accessible long running service tasks not blocking sub-sequent AJAX service requests in an ASP.NET Compatibility/Sessions enabled environment?

1条回答
2楼-- · 2020-04-30 02:52

The answer is here...

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?

By changing the SessionStateBehavior of the callback service, I was able to isolate this service to be run non-sequentially and stop the blockages.

Thanks Cine (https://stackoverflow.com/users/264022/cine)

查看更多
登录 后发表回答