我正在處理需要異步Web服務調用的Asp.Net 3.5 Web應用程序。 這是一些代碼。我已經使用委託編寫了Async調用代碼,但不知何故,我的HttpContext.Current.Session爲null。爲了確保,我甚至嘗試傳遞HttpContext。調用異步webservices時HttpContext.Current.Session爲空
static HttpContext httpContext;
public void AsyncGetUser()
{
httpContext = HttpContext.Current;//not getting Session as null here
GetUserDelegate delegate = new GetUserDelegate(InvokeWrapperMethod);
IAsyncResult async = delegate.BeginInvoke(httpContext,new AsyncCallback(CallbackMethod), null);
}
static void CallbackMethod(IAsyncResult ar)
{
AsyncResult result = (AsyncResult)ar;
GetUserDelegate caller = (GetUserDelegate)result.AsyncDelegate;
caller.EndInvoke(ar);
}
private static void InvokeWrapperMethod(HttpContext hc)
{
HttpContext.Current = hc; //getting Session as null here
UserInfo userInfo = Service.GetUserInfo();
SetInSession(USER_INFO, userInfo);
}
我試圖<modules runAllManagedModulesForAllRequests="true">
和
<system.webServer>
<modules>
<remove name="Session"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
</modules>
,因爲這SO question建議,但沒有奏效。如果你們能提供一些建議,我將不勝感激。謝謝。
我試過了,但遇到同樣的錯誤。 – Krishna 2012-04-24 21:27:01
在什麼課上?在代理上調用BeginInvoke時,不涉及任何接口。或者是? – Schultz9999 2013-03-15 21:12:53