lundi 12 février 2018

Call Soap web service without adding service reference

I need to call a web service without adding a service reference

I am currently sending a soap request using the code below

 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.Headers.Add("SOAPAction", "http://tempuri.org/GetAuthenticationKey");
        req.ContentType = "text/xml;charset=\"utf-8\"";
        req.Accept = "text/xml";
        req.Method = "POST";

        using (Stream stm = req.GetRequestStream())
        {

            using (StreamWriter stmw = new StreamWriter(stm))
            {
                stmw.Write(soapStr);
            }
        }

<?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>
<GetAuthenticationKey xmlns="http://tempuri.org/">
<appSecurityKey></appSecurityKey>
<userName></userName>
<password></password>
</GetAuthenticationKey>
</soap:Body></soap:Envelope>

but I am getting the following error The remote server returned an error: (500) Internal Server Error.

Can anyone please tell me what is wrong with my request?

Please note that soapStr is the xml pasted above I am tried calling the service using soap UI and same xml and could get response




Aucun commentaire:

Enregistrer un commentaire