469,913 Members | 2,234 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,913 developers. It's quick & easy.

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 2372
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jeff B | last post: by
1 post views Thread by Brent | last post: by
6 posts views Thread by Russell Stevens | last post: by
reply views Thread by felippe | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.