1

I am stuck with this, I am calling a simple report server URL which returns report's PDF, but strangely the WebRequest.GetResponse method doesn't return anything, when I say this, I mean the code just stop executing at that point, no exception, no error, no status code, no event viewer log on server, nothing!! And so I am not able to debug it

This is my code

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.PreAuthenticate = true;
req.UseDefaultCredentials = true;
req.Credentials = CredentialCache.DefaultNetworkCredentials;
req.ImpersonationLevel = TokenImpersonationLevel.Impersonation;
req.Timeout = int.MaxValue;

Log.Write("Log before");

var response = req.GetResponse();

Log.Write("Log after");

It just prints Log before log and then nothing is printed after that.

This code works perfectly fine when I run through visual studio and stops working when it is deployed in dev and test servers!

I am just expecting it to atleast through the exception or return unauthorized or any other status code, then I will be able to debug the issue.

Any suggestions what I can try to debug it?

Pawan Nogariya
  • 8,330
  • 12
  • 52
  • 105

1 Answers1

2

Have you tried leaving it for 24 days 20 hours 31 minutes and 24 seconds? In other words, have you left it for as long as you have set the timeout to?

The server is not returning a response and the code is waiting int.MaxValue milliseconds to tell you that. The most likely cause of this is that there is a piece of networking infrastructure between your client and server that is stopping the request. This could be a firewall or proxy. It may also be being caused by the server not liking the request and refusing to respond.

Things I would try:

  1. Try accessing the URL though a web browser on the machine that the code is failing on.
  2. Set the timeout to something sensible like one minute and run the request to timeout.
  3. Try pinging the remote server from the client machine.
  4. Use a product like Fiddler to check what is actually being sent and received.
  5. Have a chat with your network provider to see if they can help.
  6. Check the server logs to see if the server has erred.
  7. Change the first log to Log.Write("Log before: " + url); to check what is actually being requested.
Martin Brown
  • 24,692
  • 14
  • 77
  • 122
  • Thanks @martin.Actually I already tried point `7` and the URL is correct, I did not post my whole but actually I tried logging many information. Point `1` I am going to try, however I already tried putting a simple anchor on my page with the same link & it shows me the PDF. I will try to hit the URL directly from the server in sometime. About point `2`, actually earlier I did not use timeout thing at all,but then also it was not working, I put this timeout after that just for testing. Point `6`, I already checked event viewer of server before posting questing and nothing was there as well :( – Pawan Nogariya Oct 06 '16 at 08:47