500 internal server error at GetResponse() 500 internal server error at GetResponse() asp.net asp.net

500 internal server error at GetResponse()


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();                }}


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.


Finally I get rid of internal server error message with the following code. Not sure if there is another way to achieve it.

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);    }}using (WebResponse webResponse = request.GetResponse()){}