By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,016 Members | 2,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,016 IT Pros & Developers. It's quick & easy.

DirectCast Timeout issue HttpWebResponse

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.