开发者

httpwebrequest BeginGetResponse callback fires in 60 Seconds WP7

开发者 https://www.devze.com 2023-04-03 13:30 出处:网络
I am trying to fetch some data toWP7 device using a websevice. I am using HttpWebRequest object to get the data from my service... everything works well on WP7 Emulator, but when i try to run the app

I am trying to fetch some data to WP7 device using a websevice.

I am using HttpWebRequest object to get the data from my service... everything works well on WP7 Emulator, but when i try to run the application on WP7 device BeginGetResponse callback fires after 1 min/60 seconds with response status "Not Found".

But if service returns data before 60 seconds then it works on WP7 device as well...开发者_开发知识库.

i have crated a sample web service with a sample method which has Thread.Sleep for two minutes it works on WP7 Emulator but not working on WP7 device....

did anybody faces any issue like this before???

Please help me out.

Thanks, SK


I am using below code to hit the service... same code is working on WP7 Emulator but on WP7 device...

        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);
0

精彩评论

暂无评论...
验证码 换一张
取 消