Показать недружественную ошибку HTTP 500 в Visual Studio - PullRequest
2 голосов
/ 26 июля 2010

Я пишу приложение, которое отправляет XML на веб-сервис, и меня постоянно встречают с WebException, утверждающим ошибку HTTP 500 на сервере. Есть ли в любом случае, чтобы увидеть специфику ошибки, сродни "недружественным" сообщениям об ошибках в Internet Explorer?

Кнопка «Подробнее» не отображает точный ответ сервера, который я ищу.

Спасибо.

Вот код и точное сообщение об ошибке:

static void Main(string[] args)
    {   


        //create requester
        WebRequest request = WebRequest.Create("http://server.com/service");

        //create string of xml to transfer
        string xml = "<xml>some xml goes here</xml>";

        //convert string to byte array
        byte[] transfer = Encoding.ASCII.GetBytes(xml);

        //set up method
        request.Method = "POST";

        //set up content type
        request.ContentType = "text/xml";

        //set up content length
        request.ContentLength = transfer.Length;

        //open data stream
        Stream myStream = request.GetRequestStream();

        //send the data
        myStream.Write(transfer, 0, transfer.Length);

        //Create object to capture response
       WebResponse response = request.GetResponse(); 

        //Create object to convert response to readable form
       StreamReader reader = new StreamReader(response.GetResponseStream()); 


        //Reach each line of the response stream and display on command line
       string str = reader.ReadLine();
       while(str != null)
       {
            Console.WriteLine(str);
            str = reader.ReadLine();
       }

       Console.ReadLine();

    }

System.Net.WebException не обработан Сообщение = "Удаленный сервер возвратил ошибку: (500) Внутренняя ошибка сервера." Источник = «Система» Трассировки стека: в System.Net.HttpWebRequest.GetResponse () в SOAP_Test.Program.Main (String [] args) в строке 41 в System.AppDomain._nExecuteAssembly (сборка сборки, аргументы String []) в System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String [] args) в Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly () в System.Threading.ThreadHelper.ThreadStart_Context (состояние объекта) в System.Threading.ExecutionContext.Run (ExecutionContext executeContext, обратный вызов ContextCallback, состояние объекта) в System.Threading.ThreadHelper.ThreadStart () InnerException:

1 Ответ

1 голос
/ 26 июля 2010

Перехватите исключение и отобразите сообщение и исключение, если оно доступно.

...