DirectCast Timeout issue HttpWebResponse

S

stewart.fay

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top