在 WP7 上使用 HttpWebRequest 时,Request.EndGetResponse 抛出“Not Found” 1分钟后出错
我正在使用 HttpWebRequest 从 WP7 调用 Web 服务。
在 WP7 模拟器上一切正常,但当我使用 WP7 设备时,如果 Web 服务在 1 分钟内没有响应,它会抛出“未找到”异常。
我没有找到任何属性来增加 WP7 框架中 HttpWebRequest 的超时。
下面是我正在使用的代码
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
var res = request.BeginGetRequestStream(
new AsyncCallback((streamResult) =>
{
byte[] requestBytes = Encoding.UTF8.GetBytes(soapRequestEnvelope);
try
{
using (Stream requestStream = request.EndGetRequestStream(streamResult))
{
requestStream.Write(requestBytes, 0, Encoding.UTF8.GetByteCount(soapRequestEnvelope));
}
}
catch (Exception e)
{
}
request.BeginGetResponse(new AsyncCallback((ar) =>
{
try
{
HttpWebRequest Request = (HttpWebRequest)ar.AsyncState;
if (Request != null)
{
//below line throws error if response doesn't come in 1 Minute
using (HttpWebResponse webResponse = (HttpWebResponse)Request.EndGetResponse(ar))
{
StreamReader reader = new StreamReader(webResponse.GetResponseStream());
//Response comes here
string text = reader.ReadToEnd();
}
}
}
catch (Exception ex)
{
}
}), request);
}), request);
请帮帮我吗?
谢谢, SK
I am using HttpWebRequest to call a webservice from WP7.
Everything works fine on WP7 emulator but when i use WP7 device, it throws "Not Found" exception if webservice doesn't respond in 1 minute.
i did not find any property to increase the timeout of HttpWebRequest in WP7 framework.
below is code i am using
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
var res = request.BeginGetRequestStream(
new AsyncCallback((streamResult) =>
{
byte[] requestBytes = Encoding.UTF8.GetBytes(soapRequestEnvelope);
try
{
using (Stream requestStream = request.EndGetRequestStream(streamResult))
{
requestStream.Write(requestBytes, 0, Encoding.UTF8.GetByteCount(soapRequestEnvelope));
}
}
catch (Exception e)
{
}
request.BeginGetResponse(new AsyncCallback((ar) =>
{
try
{
HttpWebRequest Request = (HttpWebRequest)ar.AsyncState;
if (Request != null)
{
//below line throws error if response doesn't come in 1 Minute
using (HttpWebResponse webResponse = (HttpWebResponse)Request.EndGetResponse(ar))
{
StreamReader reader = new StreamReader(webResponse.GetResponseStream());
//Response comes here
string text = reader.ReadToEnd();
}
}
}
catch (Exception ex)
{
}
}), request);
}), request);
Pleae help me out?
Thanks,
SK
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您没有调用本地 Web 服务,您的设备无法解析本地主机而不是模拟器
Be sure that you're not calling a local web service, your device is not able to resolve localhost instead of emulator