Webrequest.GetResponse() Hangs after three or four times

Dear ALL

I am using visual studio 2003.

I use  this function for get the html file from web server .
----------------------------------------------
Public Shared Function GetResponseStringA(ByVal RemoteURL As String) As String

Dim StartTime As DateTime = DateTime.Now()
Dim DownloadContent As String
Dim objRequest As Net.WebRequest, objResponse As Net.WebResponse,
objStreamReceive As System.IO.Stream, objEncoding As
System.Text.Encoding, objStreamRead As System.IO.StreamReader

Try
    DownloadContent = ""
    objRequest = Net.WebRequest.Create(RemoteURL)
   
    objResponse = objRequest.GetResponse
    objStreamReceive = objResponse.GetResponseStream
    objEncoding = System.Text.Encoding.GetEncoding("utf-8")
    objStreamRead = New System.IO.StreamReader(objStreamReceive,
objEncoding)
    DownloadContent = objStreamRead.ReadToEnd()
   
    If Not objResponse Is Nothing Then
        objResponse.Close()
    End If
   
    Return DownloadContent
Catch ex As Exception
     msgbox(ex.message)
End Try

End Function
--------------------------------------------------------------

This function works finely for few times

After five or six times . It hangs on the line
           objResponse = objRequest.GetResponse.

How to fix that problem

Prakash
LVL 10
prakash_prkAsked:
Who is Participating?
 
NetminderCommented:
Closed, 250 points refunded.
Netminder
Site Admin
0
 
gregoryyoungCommented:
could you define "hangs" ? does it hang indefinately or does it eventually come back with an exception ?

0
 
prakash_prkAuthor Commented:

It means that .

It waits for a long time  and throws a  timeout exception for all requests after three or four times.

At the time I check that request URL in IE .It works fine.

How to solve this error gregoryyoung

bye
Prakash


0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
gregoryyoungCommented:
ok, so its timing out while IE still works ? what type of network are you running on ? wireless lan serial etc.
0
 
prakash_prkAuthor Commented:

I am testing with my PPC 2002 Emulator.

My Network a simple LAN of ten Computers connected to a network switch.
0
 
gregoryyoungCommented:
well on the emulator i would put it as pretty likely that its the emulator causing it. You can only use an emulator for your most basic testing, a real device is absolutly needed.
0
 
prakash_prkAuthor Commented:

Thank you for giving a good idea  gregoryyoung . I don't think on that area.

I try to  check my code in a PPC device

Thank you very much
Prakash

0
 
prakash_prkAuthor Commented:

hi  gregoryyoung .

The error Continous my PPC Device also  gregoryyoung.

what I to do ??

bye
Prakash
0
 
gregoryyoungCommented:
ok ... lets try to write a very simple program that only has a button and a hard coded call to yahoo.com .... do you get the same behavior ?
0
 
prakash_prkAuthor Commented:
Hi gregoryyoung

I found the solution ..

It is a simple mistake by myself.

I have one more function in my program named UploadFile() it uploads a file to server from PDA.
I didn't  call the close method of WebResponse,WebRequest,Stream objects in the UploadFile() . On this day I see this code and add close methods the code .
The web response in GetResponseString() works well.

There is no link between this two functions. both of them are resides in different Classes. Both of them uses different variables ??

What going wrong ???

0
 
prakash_prkAuthor Commented:

Hi gregoryyoung

Thank you for your good suggesstions.

reagrds
Prakash

0
 
gregoryyoungCommented:
they use the same underlying code in the framework ... it may have been that you were leaving open file handles ...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.