1

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

  • I saw something similar, when an assembly was not updated correctly. So the w3wp was using an older assembly than i had in vs. – TGlatzer Feb 20 '13 at 11:34
  • @Grumbler85 Thanks for your answer! Originally this code is part of an assembly. But here, for my test, I wrote a basic console app doing the same job. Do you think the problem you mentioned could happen in that situation? – killuminiiiou Feb 20 '13 at 13:38
  • No that's unlikely - i saw it in some circumstances with w3wp, but never from a console app. But did you step through with the debugger? – TGlatzer Feb 20 '13 at 13:49
  • @Grumbler85 I don't have access to the remote device from my dev machine. So until now, I was building the app and then testing it from a server where I had access to the device. I found another server on which I could have installed VS to debug, but it seems now all devices we have are in a "normal" state so I can't reproduce the issue I was having... :( – killuminiiiou Feb 20 '13 at 15:11

0 Answers0