473,763 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(oWeb Request.GetResp onse, HttpWebResponse )

Does anyone have any ideas why this timeouts in the code, but not the
browser?

Code:
'Issue the Request
Try
oWebRequest =
DirectCast(WebR equest.Create(m _sURIString), HttpWebRequest)
oWebRequest.Met hod = "POST"
oWebRequest.Con tentType = "text/xml"
oWebRequest.Kee pAlive = False 'False cos were only
sending one request
oWebRequest.Con tentLength = sRequest.Length
oWebRequest.Tim eout = iTimeout
oStmWriter = New
StreamWriter(oW ebRequest.GetRe questStream)

oStmWriter.Writ e(sRequest)
oStmWriter.Flus h() 'make sure its done

LogMessage(m_oE ventLog, "Posted request - " +
m_sXMLFile)

Catch WebEx As Net.WebExceptio n
Throw New AppException("G enerated Web Exception:" &
WebEx.Message.T oString, _
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(oWeb Request.GetResp onse,
HttpWebResponse )
oStmReader = New
StreamReader(oW ebResponse.GetR esponseStream)
'Set the Response to a nice string
sResponse = oStmReader.Read ToEnd
LogMessage(m_oE ventLog, "Response recieved - " +
m_sXMLFile)

'Put the XML String into an XML document so that we can
read it nicely
oXMLResponse.Lo adXml(sResponse )

Finally
oStmWriter.Clos e()
If Not IsNothing(oStmR eader) Then
oStmReader.Clos e()
End If

If Not IsNothing(oWebR esponse) Then
oWebResponse.Cl ose()
oWebResponse = Nothing
End If

oStmWriter = Nothing
oStmReader = Nothing
oWebRequest = Nothing
oXML = Nothing
End Try

Aug 2 '06 #1
1 3448
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*********@an ite.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(oWeb Request.GetResp onse, HttpWebResponse )

Does anyone have any ideas why this timeouts in the code, but not the
browser?

Code:
'Issue the Request
Try
oWebRequest =
DirectCast(WebR equest.Create(m _sURIString), HttpWebRequest)
oWebRequest.Met hod = "POST"
oWebRequest.Con tentType = "text/xml"
oWebRequest.Kee pAlive = False 'False cos were only
sending one request
oWebRequest.Con tentLength = sRequest.Length
oWebRequest.Tim eout = iTimeout
oStmWriter = New
StreamWriter(oW ebRequest.GetRe questStream)

oStmWriter.Writ e(sRequest)
oStmWriter.Flus h() 'make sure its done

LogMessage(m_oE ventLog, "Posted request - " +
m_sXMLFile)

Catch WebEx As Net.WebExceptio n
Throw New AppException("G enerated Web Exception:" &
WebEx.Message.T oString, _
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(oWeb Request.GetResp onse,
HttpWebResponse )
oStmReader = New
StreamReader(oW ebResponse.GetR esponseStream)
'Set the Response to a nice string
sResponse = oStmReader.Read ToEnd
LogMessage(m_oE ventLog, "Response recieved - " +
m_sXMLFile)

'Put the XML String into an XML document so that we can
read it nicely
oXMLResponse.Lo adXml(sResponse )

Finally
oStmWriter.Clos e()
If Not IsNothing(oStmR eader) Then
oStmReader.Clos e()
End If

If Not IsNothing(oWebR esponse) Then
oWebResponse.Cl ose()
oWebResponse = Nothing
End If

oStmWriter = Nothing
oStmReader = Nothing
oWebRequest = Nothing
oXML = Nothing
End Try

Aug 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3178
by: Joey Chömpff | last post by:
Hello, When I'm uploading an file to a JRun WebServer (third party) with a Windows Forms application, l always get an TimeOut while uploading, all other request who doesn't request an post are going ok? Why? I've tried almost everything. I also tried the KB888528 solution but this also doesn't work. What can the KB887563 do for me? Machine( tried on Windows 2003 Server & WinXp)
1
3446
by: Jason Manfield | last post by:
I have the following URL: http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&u=/netahtml/search-adv.htm&r=2&p=1&f=G&l=50&d=ptxt&S1=((teeth+OR+member)+OR+provide)&OS=+(teeth+OR+member)+OR+provide&RS=((teeth+OR+member)+OR+provide) Accessing it with the following code snippet (which works for other sites): HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); ...
1
12609
by: Jeff B | last post by:
I'm trying to create a simple screen scraping application and I kept getting a System.Net.WebException thrown back with a message of "The operation has timed-out." At first I thought it was some kind of connectivity issue on the machine. It didn't make sense though, because I can open up a browser on the same machine and easily browse the web. I'm stumped. I looked over my code for any errors and just couldn't find what I was doing...
2
2606
by: Noggin The Nog | last post by:
Hi all, I've been trying to get HttpWebResponse to work, but whenever I try I get "The operation has timed-out". I'm simply trying to send an HTTP request querystring to a remote website and read back the single string it returns (OK/Not-Ok)! It seems such a simple thing to do, but I've been on this for hours now! Here's the code I'm trying: Dim myRequest As HttpWebRequest Dim myResponse As HttpWebResponse
1
4037
by: Brent | last post by:
I thought I was doing a simple thing, here -- asking a server for a text document, getting the first 150 lines, and then returning the lines. But I keep getting timeout errors: "Exception Details: System.Net.WebException: The operation has timed-out." I read somewhere that generally these errors come from not closing a HTTPWebResponse connection before opening another. But -- to my knowledge -- I've shut down connections in every way I...
6
4329
by: Russell Stevens | last post by:
I use a WinForm app for users to upload a file to my server. Basically one line of code; Response = WC.UploadData(MyUrl, "PUT", MyByteArray) Works fine except for larger files. After about 104 seconds I get a System.Net.WebException in System.dll. The message is "The operation has timed out". On my server, I have modified the machine.config file for the httpRuntime
1
3777
by: felippe | last post by:
Hi! I have got IIS 6.0 on Windows 2003 Server. I have installed HTTP handler (as simple reverse-proxy) - code below. I created virtual category with this dll and Wilcard application mapping set to aspnet_isapi.dll Now everything works fine, but sometimes IIS stops working and return 'Error in /catalog Application. Request timeout...' And than i must restart IIS (at least application pools).
0
1280
by: felippe | last post by:
Hi! I have got IIS 6.0 on Windows 2003 Server. I have installed HTTP handler (as simple reverse-proxy) - code below. I created virtual category with this dll and Wilcard application mapping set to aspnet_isapi.dll Now everything works fine, but sometimes IIS stops working and return 'Error in /catalog Application. Request timeout...' And than i must restart IIS (at least application pools).
2
9694
by: GHS | last post by:
I have some code to connect to a website and pull some content out of the HTML. I've verified that the 2 URLs I'm using are perfectly fine in Internet Explorer and both of them return results "pretty quickly". The first URL I try takes a while but eventually comes back with the correct results. It took *much longer* than in Internet Explorer. The second URL times out even if I increase the timeout value significantly. Internet explorer...
0
9389
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7370
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5271
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5410
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3918
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3529
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2797
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.