缺少ASP.NET Web服务根元素(控制台应用程序)C#
我想知道是否有人能帮我。我正在尝试连接到托管在虚拟机IIS上的Web服务。我可以通过计算机上的Microsoft Edge和虚拟机上的localhost连接到web服务 我正试图通过使用POST方法的VisualStudio通过计算机上的控制台应用程序连接到它。我已经尝试过GET方法,它工作得很好,但是我希望能够使用POST方法 这是我的控制台应用程序缺少ASP.NET Web服务根元素(控制台应用程序)C#,c#,asp.net,web,service,C#,Asp.net,Web,Service,我想知道是否有人能帮我。我正在尝试连接到托管在虚拟机IIS上的Web服务。我可以通过计算机上的Microsoft Edge和虚拟机上的localhost连接到web服务 我正试图通过使用POST方法的VisualStudio通过计算机上的控制台应用程序连接到它。我已经尝试过GET方法,它工作得很好,但是我希望能够使用POST方法 这是我的控制台应用程序 WebRequest request = WebRequest.Create("WebServiceUrl");
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无法处理请求。-->缺少根元素
一些帮助会很好,因为我对控制台应用程序中导致错误的原因有点茫然。谢谢。您能提到完整的异常吗?这是一个SOAP错误。看这里: