отправить запрос soap c#
Всем привет,
Надеюсь, кто-нибудь сможет помочь. Я продолжаю получать "внутреннюю ошибку сервера 500" с этим кодом. Я начинаю сходить с ума.
Вот код:
public static void getAuthenticationToken() { StringBuilder xml = new StringBuilder(); xml.Append(@"<?xml version=""1.0"" encoding=""utf-8""?>"); xml.Append(@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" "); xml.Append(@"xmlns:ser=""http://www.UKMail.com/Services/Contracts/ServiceContracts"" "); xml.Append(@"xmlns:dat=""http://www.UKMail.com/Services/Contracts/DataContracts"">"); xml.Append("<soapenv:Header/>"); xml.Append("<soapenv:Body>"); xml.Append("<ser:Login>"); xml.Append("<ser:loginWebRequest>"); xml.Append("<dat:Password>password</dat:Password>"); xml.Append("<dat:Username>username</dat:Username>"); xml.Append("</ser:loginWebRequest>"); xml.Append("</ser:Login>"); xml.Append("</soapenv:Body>"); xml.Append("</soapenv:Envelope>"); string s = getUKMailData(xml.ToString(), "https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl"); } public static void getUKMailData(string xml, string address) { string result = ""; HttpWebRequest request = CreateWebRequest(address); XmlDocument soapEnvelopeXml = new XmlDocument(); soapEnvelopeXml.LoadXml(xml); using (Stream stream = request.GetRequestStream()) { soapEnvelopeXml.Save(stream); } using (WebResponse response = request.GetResponse()) // Error occurs here { using (StreamReader rd = new StreamReader(response.GetResponseStream())) { string soapResult = rd.ReadToEnd(); Console.WriteLine(soapResult); } } } public static HttpWebRequest CreateWebRequest(string url) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Headers.Add("SOAP:Action"); webRequest.ContentType = "text/xml;charset=\"utf-8\""; webRequest.Accept = "text/xml"; webRequest.Method = "POST"; return webRequest; }
Я новичок в SOAP и не знаю, как заставить его работать в .NET. Любая помощь будет оценена по достоинству.
Sergey Alexandrovich Kryukov
Вы думаете, что только начинаете? Хочешь поговорить об этом? :-)
—СА