473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DirectCast Timeout issue HttpWebResponse

Dear all,

I am using the HttpWebRequest and HttpWebRequest to send an XML request
to an ASPX page.

When I use the browser and add my XML request the request is posted
fine and an answer is retrieved.

However, when I use the code below I get an timeout error on the line:
oWebResponse = DirectCast(oWebRequest.GetResponse, HttpWebResponse)

Does anyone have any ideas why this timeouts in the code, but not the
browser?

Code:
'Issue the Request
Try
oWebRequest =
DirectCast(WebRequest.Create(m_sURIString), HttpWebRequest)
oWebRequest.Method = "POST"
oWebRequest.ContentType = "text/xml"
oWebRequest.KeepAlive = False 'False cos were only
sending one request
oWebRequest.ContentLength = sRequest.Length
oWebRequest.Timeout = iTimeout
oStmWriter = New
StreamWriter(oWebRequest.GetRequestStream)

oStmWriter.Write(sRequest)
oStmWriter.Flush() 'make sure its done

LogMessage(m_oEventLog, "Posted request - " +
m_sXMLFile)

Catch WebEx As Net.WebException
Throw New AppException("Generated Web Exception:" &
WebEx.Message.ToString, _
ExceptionLevel.Failure, "Sending Request to
URI")
Catch ex As Exception
Throw New AppException(ex.Message,
ExceptionLevel.Failure, "Sending Request to URI")
End Try

'Now read the repsonse
Try
'Read the response coming back from the website
oWebResponse = DirectCast(oWebRequest.GetResponse,
HttpWebResponse)
oStmReader = New
StreamReader(oWebResponse.GetResponseStream)
'Set the Response to a nice string
sResponse = oStmReader.ReadToEnd
LogMessage(m_oEventLog, "Response recieved - " +
m_sXMLFile)

'Put the XML String into an XML document so that we can
read it nicely
oXMLResponse.LoadXml(sResponse)

Finally
oStmWriter.Close()
If Not IsNothing(oStmReader) Then
oStmReader.Close()
End If

If Not IsNothing(oWebResponse) Then
oWebResponse.Close()
oWebResponse = Nothing
End If

oStmWriter = Nothing
oStmReader = Nothing
oWebRequest = Nothing
oXML = Nothing
End Try

Aug 2 '06 #1
1 3416
I have a silly response, why are you doing it this way instead of just adding
the web service as a Web Reference?

======================================
David McCarter
www.vsdntips.com
VSDN Tips & Tricks .NET Coding Standards available at:
www.cafepress.com/vsdntips.20412485
"st*********@anite.com" wrote:
Dear all,

I am using the HttpWebRequest and HttpWebRequest to send an XML request
to an ASPX page.

When I use the browser and add my XML request the request is posted
fine and an answer is retrieved.

However, when I use the code below I get an timeout error on the line:
oWebResponse = DirectCast(oWebRequest.GetResponse, HttpWebResponse)

Does anyone have any ideas why this timeouts in the code, but not the
browser?

Code:
'Issue the Request
Try
oWebRequest =
DirectCast(WebRequest.Create(m_sURIString), HttpWebRequest)
oWebRequest.Method = "POST"
oWebRequest.ContentType = "text/xml"
oWebRequest.KeepAlive = False 'False cos were only
sending one request
oWebRequest.ContentLength = sRequest.Length
oWebRequest.Timeout = iTimeout
oStmWriter = New
StreamWriter(oWebRequest.GetRequestStream)

oStmWriter.Write(sRequest)
oStmWriter.Flush() 'make sure its done

LogMessage(m_oEventLog, "Posted request - " +
m_sXMLFile)

Catch WebEx As Net.WebException
Throw New AppException("Generated Web Exception:" &
WebEx.Message.ToString, _
ExceptionLevel.Failure, "Sending Request to
URI")
Catch ex As Exception
Throw New AppException(ex.Message,
ExceptionLevel.Failure, "Sending Request to URI")
End Try

'Now read the repsonse
Try
'Read the response coming back from the website
oWebResponse = DirectCast(oWebRequest.GetResponse,
HttpWebResponse)
oStmReader = New
StreamReader(oWebResponse.GetResponseStream)
'Set the Response to a nice string
sResponse = oStmReader.ReadToEnd
LogMessage(m_oEventLog, "Response recieved - " +
m_sXMLFile)

'Put the XML String into an XML document so that we can
read it nicely
oXMLResponse.LoadXml(sResponse)

Finally
oStmWriter.Close()
If Not IsNothing(oStmReader) Then
oStmReader.Close()
End If

If Not IsNothing(oWebResponse) Then
oWebResponse.Close()
oWebResponse = Nothing
End If

oStmWriter = Nothing
oStmReader = Nothing
oWebRequest = Nothing
oXML = Nothing
End Try

Aug 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joey Chömpff | last post by:
Hello, When I'm uploading an file to a JRun WebServer (third party) with a Windows Forms application, l always get an TimeOut while uploading, all other request who doesn't request an post are...
1
by: Jason Manfield | last post by:
I have the following URL: ...
1
by: Jeff B | last post by:
I'm trying to create a simple screen scraping application and I kept getting a System.Net.WebException thrown back with a message of "The operation has timed-out." At first I thought it was some...
2
by: Noggin The Nog | last post by:
Hi all, I've been trying to get HttpWebResponse to work, but whenever I try I get "The operation has timed-out". I'm simply trying to send an HTTP request querystring to a remote website and read...
1
by: Brent | last post by:
I thought I was doing a simple thing, here -- asking a server for a text document, getting the first 150 lines, and then returning the lines. But I keep getting timeout errors: "Exception...
6
by: Russell Stevens | last post by:
I use a WinForm app for users to upload a file to my server. Basically one line of code; Response = WC.UploadData(MyUrl, "PUT", MyByteArray) Works fine except for larger files. After about 104...
1
by: felippe | last post by:
Hi! I have got IIS 6.0 on Windows 2003 Server. I have installed HTTP handler (as simple reverse-proxy) - code below. I created virtual category with this dll and Wilcard application mapping set to...
0
by: felippe | last post by:
Hi! I have got IIS 6.0 on Windows 2003 Server. I have installed HTTP handler (as simple reverse-proxy) - code below. I created virtual category with this dll and Wilcard application mapping set to...
2
by: GHS | last post by:
I have some code to connect to a website and pull some content out of the HTML. I've verified that the 2 URLs I'm using are perfectly fine in Internet Explorer and both of them return results...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.