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 1 1320
This sends your data to them by grabbing a hold of the request stream and
writing
data to it.
Dim myRequestBodyStream As Stream = myWebRequest.GetRequestStream myRequestBodyStream.Write(bodyBytes, 0, bodyBytes.Length)
myRequestBodyStream.Close()
This gets the response stream and shoves it in a local stream reader. So,
yes this
is why it takes so long
Dim myResponseStream As New
StreamReader(myResponse.GetResponseStream, System.Text.Encoding.ASCII)
This takes the local streamreader and converts it to a string.
Dim myResponseBody As String = myResponseStream.ReadToEnd myResponseStream.Close()
--
2004 and 2005 Microsoft MVP C#
Robbe Morris http://www.masterado.net
Earn $$$ money answering .NET Framework
messageboard posts at EggHeadCafe.com. http://www.eggheadcafe.com/forums/merit.asp
"Dave56" <no****@co.lane.or.us> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John K. |
last post by:
Hi
I was wondering if it's possible to use the WebRequest class to access a file on windows shared folder with authentication? If yes, what would the syntax be? I've tried to look this up in the...
|
by: Terry |
last post by:
Hello,
I am trying to get a response for an .aspx page in my current project (same
virtual directory) by using WebRequest.GetResponse but I keep getting a
exception with "500 Internal server...
|
by: james.dixon |
last post by:
Hi
I have been struggling with what should be a simple thing. I want to
crawl the web for specific links, and save any html and files that meet
my criteria to my hard drive.
I thought that...
|
by: buccsailor |
last post by:
Hell there,
I tried to post a reply to a message thread created back in July 2006
regarding the override of WebRequest, Closed Conenctions and setting
KeepAlive to false,but it's been over 60...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |