Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

500 internal server error at GetResponse()

I have a heavy traffic aspx page calling a web service upon every user`s request as follows.

string uri = "Path.asmx"; string soap = "soap xml string";  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Headers.Add("SOAPAction", "\"http://xxxxxx""); request.ContentType = "text/xml;charset=\"utf-8\""; request.Accept = "text/xml"; request.Method = "POST";  using (Stream stm = request.GetRequestStream()) {     using (StreamWriter stmw = new StreamWriter(stm))     {         stmw.Write(soap);     } } WebResponse response = request.GetResponse(); response.close(); 

Everything is working fine but sometimes I am getting the following error.

The remote server returned an error: (500) Internal Server Error. at System.Net.HttpWebRequest.GetResponse()

Does anybody have any idea about this error or can anybody tell me if I am doing wrong.

like image 343
Krishna Avatar asked Nov 04 '10 16:11

Krishna


2 Answers

For me this error occurred because I had 2 web API actions that had the exact same signatures and both had the same verbs, HttpPost, what I did was change one of the verbs (the one used for updating) to PUT and the error was removed. The following in my catch statement helped in getting to the root of the problem:

catch (WebException webex) {                 WebResponse errResp = webex.Response;                 using (Stream respStream = errResp.GetResponseStream())                 {                     StreamReader reader = new StreamReader(respStream);                     string text = reader.ReadToEnd();                 } } 
like image 82
Mohammad Sepahvand Avatar answered Oct 01 '22 12:10

Mohammad Sepahvand


From that error, I would say that your code is fine, at least the part that calls the webservice. The error seems to be in the actual web service.

To get the error from the web server, add a try catch and catch a WebException. A WebException has a property called Response which is a HttpResponse. you can then log anything that is returned, and upload you code. Check back later in the logs and see what is actually being returned.

like image 37
FallenAvatar Avatar answered Oct 01 '22 12:10

FallenAvatar