【问题标题】:httpwebrequest BeginGetResponse callback fires in 60 Seconds WP7httpwebrequest BeginGetResponse 回调在 60 秒内触发 WP7
【发布时间】:2011-11-13 14:13:04
【问题描述】:

我正在尝试使用网络服务将一些数据提取到 WP7 设备。

我正在使用 HttpWebRequest 对象从我的服务中获取数据...在 WP7 模拟器上一切正常,但是当我尝试在 WP7 设备上运行应用程序时,BeginGetResponse 回调会在 1 分钟/60 秒后触发,响应状态为“不”找到”。

但如果服务在 60 秒之前返回数据,那么它也适用于 WP7 设备....

我已经使用示例方法创建了一个示例 Web 服务,该示例方法具有 Thread.Sleep 两分钟,它可以在 WP7 模拟器上运行,但不能在 WP7 设备上运行....

以前有人遇到过这样的问题吗???

请帮帮我。

谢谢, SK

【问题讨论】:

    标签: windows-phone-7 httpwebrequest timeout httpwebresponse


    【解决方案1】:

    我正在使用下面的代码来访问服务...相同的代码在 WP7 模拟器上运行,但在 WP7 设备上运行...

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    
            request.ContentType = contentType;
            request.Method = method;
    
            request.Headers["SOAPAction"] = @"http://tempuri.org/HelloWorldT";
            request.Headers["KeepAlive"] = "true";
    
            var res = request.BeginGetRequestStream(
               new AsyncCallback((streamResult) =>
               {
                   soapRequestEnvelope = @"<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><HelloWorldT xmlns='http://tempuri.org/' xmlns:a='http://schemas.datacontract.org/2004/07/WindowsFormsApplication1.ServiceReference1' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'/></s:Body></s:Envelope>";
                   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)
                           {
    
                               using (HttpWebResponse webResponse = (HttpWebResponse)Request.EndGetResponse(ar))
                               {
                                   StreamReader reader = new StreamReader(webResponse.GetResponseStream());
                                   string text = reader.ReadToEnd();
                               }
                           }
                       }
                       catch (Exception ex)
                       {
                       }
    
                   }), request);
    
    
               }), request);
    

    【讨论】:

    • 各位,有什么解决办法吗?是否有人在他们的应用程序中也遇到过这个问题...我尝试了很多东西但没有成功...这已成为我的主要障碍。请帮帮我。问候,SK
    猜你喜欢
    • 1970-01-01
    • 2011-05-24
    • 2014-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 2014-02-14
    相关资源
    最近更新 更多