我正在从 WP8 应用程序调用本地 asp.net web api 方法,并得到异常:
asyncResult.AsyncWaitHandle' 引发了“System.NotSupportedException”类型的异常
有人能帮忙吗?
public void GetProducts()
{
UriBuilder fullUri = new UriBuilder(baseUri + "productapi");
fullUri.Query = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUri.Uri);
request.Accept = "application/json";
RequestUpdateState requestState = new RequestUpdateState();
requestState.AsyncRequest = request;
request.BeginGetResponse(new AsyncCallback(HandleProductsResponse),
requestState);
}
private void HandleProductsResponse(IAsyncResult asyncResult)
{
// get the state information
RequestUpdateState requestState = (RequestUpdateState)asyncResult.AsyncState;
HttpWebRequest request = (HttpWebRequest)requestState.AsyncRequest;
// end the async request
requestState.AsyncResponse = (HttpWebResponse)request.EndGetResponse(asyncResult);
Stream streamResult;
// get the stream containing the response from the async call
streamResult = requestState.AsyncResponse.GetResponseStream();
ObservableCollection<Product> productList = new ObservableCollection<Product>();
}