locked
WebRequest on .NETCF 2.0 strange behavior. Please help RRS feed

  • Question

  • Greetings all,

    I am seeing really strange behavior. When i run my application connected through active sync i get no errors with WebRequest and no time outs. But when i run it through 3G on my phone i get a lot of different behaviours. Most of the time it does not run. Then it will run few times and crash.

    The application just times out. WebRequest behaves really strange. Its a Compact Framework 2.0 device application.

    This is the code that i am using:

     

            private MemoryStream LoadImageFromURL(string URL)
            {
                const int BYTESTOREAD = 10000;
                WebRequest myRequest = WebRequest.Create(URL);
                WebResponse myResponse = myRequest.GetResponse();
                Stream ReceiveStream = myResponse.GetResponseStream();
                BinaryReader br = new BinaryReader(ReceiveStream);
                MemoryStream memstream = new MemoryStream();
                byte[] bytebuffer = new byte[BYTESTOREAD];
                int BytesRead = br.Read(bytebuffer, 0, BYTESTOREAD);
                while (BytesRead > 0)
                {
                    memstream.Write(bytebuffer, 0, BytesRead);
                    BytesRead = br.Read(bytebuffer, 0, BYTESTOREAD);
                }
                //Img = new Bitmap(memstream);
    
                myResponse.Close();
                myResponse = null;
                myRequest = null;
                bytebuffer = null;
                ReceiveStream.Close();
    
                return memstream;
            }



    I am just passing the URL of the image to load. Quite simple.

    Any ideas?

    Any help would be appreciated.

    Looking forward to your response.


    Dan
    Sunday, May 10, 2009 4:15 PM

Answers

  • First please make sure you can open that image file in IE Mobile via 3G connection. Then you can try to read the file chunk by chunk instead. Don't forget to add some codes for error checking. A sample code is available here:

    Downloading Files with the WebRequest and WebResponse Classes
    http://www.developer.com/net/net/article.php/3340151 


    Please mark the post that helps you, and unmark that does not. This benefits our community members.
    • Marked as answer by warrentang Friday, May 15, 2009 1:58 AM
    Thursday, May 14, 2009 4:32 AM

All replies

  • Hi,

    What is the filesize of the image you are trying to download?

    Thanks

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Sunday, May 10, 2009 9:02 PM
  • 60 - 100kb
    Dan
    Sunday, May 10, 2009 9:36 PM
  • The really strange bit is that this happenes only when the application is deployed on my 3G enabled phone. When runnig in debug mode and the phone is connected to the PC through active sync and receives all communication through the computer there are no exceptions. Could there be something i have not configured properly? Sincerely Dan
    Dan
    Sunday, May 10, 2009 11:10 PM
  • First please make sure you can open that image file in IE Mobile via 3G connection. Then you can try to read the file chunk by chunk instead. Don't forget to add some codes for error checking. A sample code is available here:

    Downloading Files with the WebRequest and WebResponse Classes
    http://www.developer.com/net/net/article.php/3340151 


    Please mark the post that helps you, and unmark that does not. This benefits our community members.
    • Marked as answer by warrentang Friday, May 15, 2009 1:58 AM
    Thursday, May 14, 2009 4:32 AM
  • Hi,
      When i try to save the bitmap image in my window mobile using following code :

    myBitmap = New Bitmap(memStream)
    myBitmap.Save(sImagePath, System.Drawing.Imaging.ImageFormat.Jpeg)
    

    it throws the following error :
    Value does not fall with in expected range.
    or
    a existing connection is focibly closed by the remot host.
    so please suggest how i solve this issue.
    Thanks

    Mitesh
    Thursday, June 4, 2009 6:31 AM