D
Dave56
I have an asp.net web service that is posting data to another web server.
My code (somewhat simplified) looks like this:
'Convert string to byte array
Dim bodyBytes() As Byte = encoding.GetBytes(myString)
'Configure Http Request
Dim myWebRequest As WebRequest = WebRequest.Create(myURL)
myWebRequest.Method = "POST"
myWebRequest.ContentLength = bodyBytes.Length
myWebRequest.Timeout = 90000 '90 Seconds
'Fill the Http Request stream with XML byte array
Dim myRequestBodyStream As Stream = myWebRequest.GetRequestStream
myRequestBodyStream.Write(bodyBytes, 0, bodyBytes.Length)
myRequestBodyStream.Close()
'Get Http Response
Dim myResponse As WebResponse = myWebRequest.GetResponse
Dim myResponseStream As New
StreamReader(myResponse.GetResponseStream, System.Text.Encoding.ASCII)
'Get the Response
Dim myResponseBody As String = myResponseStream.ReadToEnd
myResponseStream.Close()
This is pretty much a black box to me...
I find that most of the time is spent on the myWebRequest.GetRequestStream
statement.
MSDN says:
- The GetRequestStream method initiates a request to send data to the
Internet resource and returns a Stream instance for sending data to the
Internet resource.
I guess I don't understand exactly what they mean by "initiates a request".
Is myWebRequest.GetRequestStream communicating with the other web server and
that is why it is taking longer?
Which statements are actually communicating with the other web server?
And which ones aren't?
Any help is greatly appreciated.
Dave
My code (somewhat simplified) looks like this:
'Convert string to byte array
Dim bodyBytes() As Byte = encoding.GetBytes(myString)
'Configure Http Request
Dim myWebRequest As WebRequest = WebRequest.Create(myURL)
myWebRequest.Method = "POST"
myWebRequest.ContentLength = bodyBytes.Length
myWebRequest.Timeout = 90000 '90 Seconds
'Fill the Http Request stream with XML byte array
Dim myRequestBodyStream As Stream = myWebRequest.GetRequestStream
myRequestBodyStream.Write(bodyBytes, 0, bodyBytes.Length)
myRequestBodyStream.Close()
'Get Http Response
Dim myResponse As WebResponse = myWebRequest.GetResponse
Dim myResponseStream As New
StreamReader(myResponse.GetResponseStream, System.Text.Encoding.ASCII)
'Get the Response
Dim myResponseBody As String = myResponseStream.ReadToEnd
myResponseStream.Close()
This is pretty much a black box to me...
I find that most of the time is spent on the myWebRequest.GetRequestStream
statement.
MSDN says:
- The GetRequestStream method initiates a request to send data to the
Internet resource and returns a Stream instance for sending data to the
Internet resource.
I guess I don't understand exactly what they mean by "initiates a request".
Is myWebRequest.GetRequestStream communicating with the other web server and
that is why it is taking longer?
Which statements are actually communicating with the other web server?
And which ones aren't?
Any help is greatly appreciated.
Dave