私は、Async Webサービス呼び出しを必要とするAsp.Net 3.5 Webアプリケーションで作業しています。 ここにいくつかのコードがあります。デリゲートを使用して非同期呼び出しのコードを書いていますが、何とか私のHttpContext.Current.Sessionはnullです。確かに、私はHttpContextを渡してみました。async 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);
}
このSO questionが提案したがうまくいかなかったように私は<modules runAllManagedModulesForAllRequests="true">
と
<system.webServer>
<modules>
<remove name="Session"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
</modules>
を試してみました。私はあなたがいくつかの指針を与えることができれば感謝します。ありがとう。
私はそれを試しましたが、同じエラーが発生しました。 – Krishna
どのクラス?デリゲートでBeginInvokeを呼び出すと、インターフェイスは関与しません。またはそれは? – Schultz9999