I was wondering if someone could help me out. I'm trying to connect to my webservice that's hosted on IIS on a vm. I am able to connect to my web service through Microsoft Edge on my computer and via localhost on the vm.
I'm trying to connect to it through a console application on my computer through Visual Studio that uses the POST method. I've tried the GET method which works fine, but I want to be able to use the POST method.
Here is my console application...
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();
Here is the exception I am getting...
Error code: InternalServerError soap:ReceiverServer was unable to process request. ---> Root element is missing.
Some help would be great, as I'm a bit lost on what's causing the error in the console application. Thank you.