httpwebrequest BeginGetResponse回调在60秒WP7中触发

时间:2011-09-09 07:55:57

标签: windows-phone-7 httpwebrequest timeout httpwebresponse

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

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

但是如果服务在60秒之前返回数据,那么它也可以在WP7设备上运行....

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

在??? ???

之前,有没有人面临这样的问题

请帮帮我。

谢谢, SK

1 个答案:

答案 0 :(得分:0)

我使用下面的代码来点击服务...相同的代码正在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);