I'm creating a simple (console) application to remote control a video device (encoder) using HTTP requests with C#. I need to send XML data to the device, and the device responds by sending XML data.
The code I'm using to do this request is the following: http://pastebin.com/59CXR3m9
When I try to test this code, the request is created and the stream is written. I can see the "stream created"
flag as expected, but then, nothing happens. Application seems to be stuck, even when I'm using a specific low timeout (5 secs for example).
To troubleshoot this, I activated System.Net
trace logging. I found a WebException
is thrown by GetRequestStream
, but for one reason, this exception is not caught by the try/catch
in my code. Here's the exception:
System.Net Error: 0 : [1344] Exception in the HttpWebRequest#44223604:: - The underlying connection was closed: The connection was closed unexpectedly.
I can send the complete trace on demand.
I also did another trace with the callstack, showing the exception is thrown by GetRequestStream
: http://pastebin.com/vE5QZGBe
I tested this code with another device and it worked fine, so this is something also device-related, but I can't see any reason why that exception would not be caught. And as this can be a production situation, the code has to be able to handle this correctly (and not wait endlessly for a response).
Did somebody already have this type of behavior? Any suggestions are greatly appreciated :)
Thanks!
FYI: I also have a trace of a successful request, if it can help