Это моя первая попытка в c # за последнее время, но я дошел до этого момента и, возможно, думаю, что мне нужны некоторые экспертные глаза на это.
Я продолжаю получать ошибку, упомянутую в названии. Я предполагаю, что есть что-то очевидное, что мне не хватает?
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace API_Call
{
class Program
{
static void Main(string[] args)
{
var watch = new Stopwatch();
HttpWebRequest request = HttpWebRequest.Create("http://bk-pim/Perfion/GetData.asmx") as HttpWebRequest;
request.Method = "POST";
request.ContentType = "text/xml";
request.Headers.Add("SOAPAction","http://perfion.com/ExecuteQuery");
//FileInfo info = new FileInfo(@"C:\Users\dcoats\Desktop\mytestfile.txt");
//long size = info.Length;
//request.ContentLength = size;
using (var stream = request.GetRequestStream())
using (var writer = new StreamWriter(stream))
{
var body = WebUtility.HtmlEncode(File.ReadAllText(@"C:\Users\dcoats\Desktop\mytestfile.txt"));
body = "<?xml version=\"1.0\" encoding=\"utf - 8\"?>< soap:Envelope xmlns:soap = \"http://schemas.xmlsoap.org/soap/envelope/\" xmlns: xsi = \"http://www.w3.org/2001/XMLSchema-instance\" xmlns: xsd = \"http://www.w3.org/2001/XMLSchema\" >< soap:Body >< ExecuteQueryResponse xmlns = \"http://perfion.com/\" >< ExecuteQueryResult >" + body + "</ExecuteQueryResult></ ExecuteQueryResponse ></ soap:Body ></ soap:Envelope > ";
}
watch.Start();
var response = request.GetResponse(); //bombs here
watch.Stop();
response.GetResponseStream();
Console.WriteLine();
Console.ReadLine();
Console.WriteLine(watch.ElapsedMilliseconds);
Console.ReadLine();
}
}
}