IAsyncResult 的 Windows 运行时类型是什么?
What is Windows Runtime Type for IAsyncResult?
我正在为 WIndows Phone 8.1 创建一个 Windows 运行时组件。我正在使用 HttpWebRequest class 调用网络服务。但是在回调函数中我必须使用 IAsyncResult 但 IAsyncResult 无效 Windows 运行时类型。
请向我推荐 IAsyncResult 的相关信息。
代码块:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(UploadServiceUrl));
webRequest.Method = "POST";
webRequest.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
webRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), webRequest);
public void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
Stream postStream = request.EndGetRequestStream(asynchronousResult);
writeMultipartObject(WindowsRuntimeStreamExtensions.AsOutputStream(postStream), data);
postStream.Dispose();
request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}
catch (Exception ex)
{
}
}
public void GetResponseCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
Stream streamResponse = response.GetResponseStream();
sResponse = new StreamReader(streamResponse).ReadToEnd();
streamResponse.Dispose();
response.Dispose();
}
catch (Exception ex)
{
}
}
编译时错误:
Error 2 Method 'XXXXXXX.XXXXXX.GetResponseCallback(System.IAsyncResult)' has parameter 'asynchronousResult' of type 'System.IAsyncResult'. 'System.IAsyncResult' is not a valid Windows Runtime parameter type.
这意味着您将此作为 WinRT 组件中 public
class 的 public
方法。只需制作方法 internal
就可以了。
我正在为 WIndows Phone 8.1 创建一个 Windows 运行时组件。我正在使用 HttpWebRequest class 调用网络服务。但是在回调函数中我必须使用 IAsyncResult 但 IAsyncResult 无效 Windows 运行时类型。
请向我推荐 IAsyncResult 的相关信息。
代码块:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(UploadServiceUrl));
webRequest.Method = "POST";
webRequest.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
webRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), webRequest);
public void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
Stream postStream = request.EndGetRequestStream(asynchronousResult);
writeMultipartObject(WindowsRuntimeStreamExtensions.AsOutputStream(postStream), data);
postStream.Dispose();
request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}
catch (Exception ex)
{
}
}
public void GetResponseCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
Stream streamResponse = response.GetResponseStream();
sResponse = new StreamReader(streamResponse).ReadToEnd();
streamResponse.Dispose();
response.Dispose();
}
catch (Exception ex)
{
}
}
编译时错误:
Error 2 Method 'XXXXXXX.XXXXXX.GetResponseCallback(System.IAsyncResult)' has parameter 'asynchronousResult' of type 'System.IAsyncResult'. 'System.IAsyncResult' is not a valid Windows Runtime parameter type.
这意味着您将此作为 WinRT 组件中 public
class 的 public
方法。只需制作方法 internal
就可以了。