Я сделал запрос SOAP с SOAPUI, и все работает нормально.Запрос равен xmlString с типом базовой аутентификации.
Мне нужно выполнить этот запрос в решении ac #, но мой код не работает:
string xmlString = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:soap=""http://soap.service.tracking.sda.it/"">
<soapenv:Header/>
<soapenv:Body>
<soap:doIt>
<arg0>
<!--Optional:-->
<codCliente>00000000001</codCliente>
<!--1 to 10 repetitions:-->
<datiSpedizione>
<!--You may enter the following 3 items in any order-->
<!--Optional:-->
<idLdv>000001</idLdv>
<!--Optional:-->
<ultimoStato>N</ultimoStato>
</datiSpedizione>
<descrizioneStatus>E</descrizioneStatus>
<!--Optional:-->
<postazione>00001</postazione>
<tipologiaCliente>SDA</tipologiaCliente>
</arg0>
</soap:doIt>
</soapenv:Body>
</soapenv:Envelope>";
HttpWebRequest request = CreateWebRequest("https://ws.sda.it/TRACKING","user","pass");
request.PreAuthenticate = true;
request.ReadWriteTimeout = 32000;
request.Timeout = 32000;
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(xmlString);
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
}
}
И это createWebRequestMethod:
public static HttpWebRequest CreateWebRequest(string url, string user, string pass)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Credentials = new NetworkCredential(user, pass);
webRequest.Headers.Add(@"SOAPAction", "TRACKING");
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
Когда я пытаюсь использовать этот код, я получаю исключение "Null reference" в запросе. GetResponse ()