在 WP7 上使用 HttpWebRequest 时,Request.EndGetResponse 抛出“Not Found” 1分钟后出错

发布于 2024-12-03 10:41:52 字数 1953 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妞丶爷亲个 2024-12-10 10:41:52

确保您没有调用本地 Web 服务,您的设备无法解析本地主机而不是模拟器

Be sure that you're not calling a local web service, your device is not able to resolve localhost instead of emulator

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文