ASP. NET Веб-служба Root Элемент отсутствует (консольное приложение) C# - PullRequest
0 голосов
/ 14 января 2020

Мне было интересно, может ли кто-нибудь мне помочь. Я пытаюсь подключиться к своему веб-сервису, который размещен на IIS на виртуальной машине. Я могу подключиться к своему веб-сервису через Microsoft Edge на моем компьютере и через localhost на виртуальной машине.

Я пытаюсь подключиться к нему через консольное приложение на моем компьютере через Visual Studio, которая использует POST метод. Я попробовал метод GET, который работает нормально, но я хочу иметь возможность использовать метод POST.

Вот мое консольное приложение ...

        WebRequest request = WebRequest.Create("WebServiceUrl");
        request.Method = "POST";
        WebResponse response = null;
        try
        {
            response = request.GetResponse();
        }
        catch(WebException exception)
        {
            using (response = exception.Response)
            {
                HttpWebResponse httpResponse = (HttpWebResponse)response;
                Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
                using (Stream data = response.GetResponseStream())
                {
                    string text = new StreamReader(data).ReadToEnd();
                    Console.WriteLine(text);
                    Console.ReadLine();
                }
            }
            Console.WriteLine(exception.ToString());
            Console.ReadLine();
        }
        Console.WriteLine(response);
        string res = response.ToString();
        Stream ReceiveStream = response.GetResponseStream();

        Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

        // Pipe the stream to a higher level stream reader with the required encoding format. 
        StreamReader readStream = new StreamReader(ReceiveStream, encode);
        Console.WriteLine("\nResponse stream received");
        Char[] read = new Char[256];

        // Read 256 charcters at a time.    
        int count = readStream.Read(read, 0, 256);
        Console.WriteLine("HTML...\r\n");

        while (count > 0)
        {
            // Dump the 256 characters on a string and display the string onto the console.
            String str = new String(read, 0, count);
            Console.Write(str);
            count = readStream.Read(read, 0, 256);
        }

        Console.WriteLine("");
        // Release the resources of stream object.
        readStream.Close();
        Console.ReadLine();

Вот исключение Я получаю ...

Код ошибки: InternalServerError soap: ReceiverServer не удалось обработать запрос. ---> Root элемент отсутствует.

Некоторая помощь была бы полезна, поскольку я немного растерялся из-за причины ошибки в консольном приложении. Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...