2

これはクラス ライブラリであり、Web ページから呼び出されています。

try
  {
    System.Net.WebClient wc = WebAccess.GetWebClient();
    wc.UploadStringCompleted += new System.Net.UploadStringCompletedEventHandler(wc_UploadStringCompleted);
    wc.UploadStringAsync(new Uri("http://" + MobileWLCUrl + urlCreateCacheAPI), GetJSONforGetMenuDetails(Id, MenuIds));                    
  }
catch (Exception ex) { EngineException.HandleException(ex); }

void wc_UploadStringCompleted(object sender, System.Net.UploadStringCompletedEventArgs e)
    {
        string result = e.Result;
        EngineException.CreateLog("Cache Created (for Menus: " + MenuIds + ") in API for LocationId: " + LocId);
    }

皆さん、この URL を非同期でアクセスしようとすると、このエラーが発生します。

Asynchronous operations are not allowed in this context. 
Page starting an asynchronous operation has to have the Async attribute set to true 
and an asynchronous operation can only be started on a page prior to PreRenderComplete event. 

at System.Web.AspNetSynchronizationContext.OperationStarted()
at System.Net.WebClient.UploadStringAsync(Uri address, String method, String data, Object userToken)
at System.Net.WebClient.UploadStringAsync(Uri address, String data)

サンクス...

4

1 に答える 1

10

Async="true"パラメータを @Page ディレクティブに追加します。

<%@ Page Async="true" ... %>

シワニ、

この変更を、"http://" + MobileWLCUrl + urlCreateCacheAPI次のコードで呼び出されるページ ( に保存)に適用する必要があります。

wc.UploadStringAsync(new Uri("http://" + MobileWLCUrl + urlCreateCacheAPI), GetJSONforGetMenuDetails(Id, MenuIds)); 
于 2012-05-18T07:43:21.610 に答える