0

I've got the following method and it behaves properly, as expected.

[OperationContract]
[WebGet(UriTemplate = "GetStuff", ResponseFormat = WebMessageFormat.Json)]
public String GetListOfTemplates()
{
  String result = "time is " + DateTime.Now.ToString("HH:mm:ss");

  try
  {
    String url = "...";
    WebRequest request = WebRequest.Create(url);
  }
  catch (Exception exception)
  {
    result = exception.Message + "\n\n" + exception.InnerException.Message;
  }

  return result;
}

However, adding an actual read to it, as exemplified e.g. here, I get the following error, so the method below doesn't work.

The server encountered an error processing the request. See server logs for more details.

[OperationContract]
[WebGet(UriTemplate = "GetStuff", ResponseFormat = WebMessageFormat.Json)]
public String GetListOfTemplates()
{
  String result = "time is " + DateTime.Now.ToString("HH:mm:ss");

  try
  {
    String url = "...";
    WebRequest request = WebRequest.Create(url);
    using (Stream stream = request.GetResponse().GetResponseStream())
      using (StreamReader reader = new StreamReader(stream))
        result = reader.ReadToEnd();
  }
  catch (Exception exception)
  {
    result = exception.Message + "\n\n" + exception.InnerException.Message;
  }

  return result;
}

There's of course the matter of why it doesn't work and how to resolve it but what baffles me (and stops me from debugging) is that the exception isn't caught and presented to the client. Also, I have no idea how to check the logs on server, since it's Azure and I'm generally confused when I don't get me dose of message in an exception. :)

Community
  • 1
  • 1
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
  • does everything work locally? There is no reason for your exception to not be caught. Something might be going wrong with the pipeline before your method gets executed! – astaykov Nov 12 '14 at 11:02
  • How is that possible? When I run the same method without the using/reading statements, I get it to fly perfectly. Or are you suggesting that it's not so perfect as it appears to me? :) – Konrad Viltersten Nov 12 '14 at 16:06
  • that does not answer the question whether the same code runs locally and catches exceptions? also, I would not put exception.InnerException call in a Catch block without checking if .InnerException is not null ... – astaykov Nov 12 '14 at 17:11
  • Sorry for being unclear. I'm not sure how to run the code locally (didn't set up IIS and I've been told that the F5-run isn't to be trusted). Anyway, I managed to discover that it's bad request, 400, because of credentials. So now I'm trying to get *WebClient* to accept *RequestBody* containing these. The answer to my question is probably that there's no error report from a WCF run as a service layer to the client. I tried to *throw* an exception by force and got the same message... :( – Konrad Viltersten Nov 12 '14 at 17:41
  • F5 is to be trusted. And you shall not tag with [AZURE] unless you proved it works flawlessly locally. Only after you are 100% sure it runs locally and there are no issues, should you blame Azure and tag Azure. People are facing general web development issues which are also issues in local environment and Blame Azure for this. Which is not politically correct ... – astaykov Nov 13 '14 at 08:38
  • Are you sure that exception has always an inner exception? Try to remove exception.InnerException.Message from result. – Fabrizio Accatino Nov 13 '14 at 10:29
  • @astaykov Just to be clear: I don't blame Azure. I blame myself. But I do so **while** working against Azure, hence the tag. I'm reluctant to develop locally because sometimes one get into trouble while deploying because suddenly there might be firewalls, slower connections and othe rstuff that one **should** but haven't considered. However, running **both** against the cloud **and** the local environment is probably a good idea. – Konrad Viltersten Nov 13 '14 at 11:15
  • @FabrizioAccatino Yupp. I don't get to see the error message even if I throw one myself. Somehow, the exception isn't caught. But I'll re-check just to be sure. Yesterday was a confused time. And I was tired. Might have done something less brilliant. :) – Konrad Viltersten Nov 13 '14 at 11:17
  • @KonradViltersten no worries. The "issue" with Azure tag is that you bring attention of Azure experts, while your problem is most likely not related to azure at all. Thus would probably get better support without tagging Azure. Everyone will always ask first "Does it run locally?". On a side note, I am really glad to hear that there are people out there in the wild developing straight into the cloud ;) – astaykov Nov 13 '14 at 12:49
  • 1
    And again, if you don't see even your exception if you explicitly throw, then the execution pipeline stops before calling your method! Check this guide: http://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-troubleshoot-visual-studio/ You can also attach Visual Studio debugger to your live Azure WebSite !! – astaykov Nov 13 '14 at 12:50
  • 1
    @astaykov Kick me. Hard. Microsoft must be playing with me. It works now. One should never code when tired or drunk, hehe. OPut your comments summarized and including the links as a reply, please. – Konrad Viltersten Nov 13 '14 at 12:55

1 Answers1

0

Does everything work locally?

There is no reason (Azure specific) for your exception to not be caught. Something might be going wrong with the pipeline before your method gets executed!

If you don't see even your exception if you explicitly throw, then the execution pipeline stops before calling your method! Check this useful guide on troubleshooting Azure Web Sites. You can also attach Visual Studio debugger to your live Azure WebSite to get even deeper insights!

astaykov
  • 30,768
  • 3
  • 70
  • 86