0

Can i send xml payload as a string to soap web service ? Is it allowed to use any http client library (Apache HttpClient, RxNetty) for the same or should i only use SAAJ framework (http://stackoverflow.com/questions/15948927/working-soap-client-example) ?

E.g.,

curl --header "Content-Type: text/xml;charset=UTF-8" 
--header "SOAPAction:http://www.webserviceX.NET/ConversionRate" 
--data @request3.xml http://www.webservicex.net/CurrencyConvertor.asmx


<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ConversionRate xmlns="http://www.webserviceX.NET/">
      <FromCurrency>USD</FromCurrency>
      <ToCurrency>GBP</ToCurrency>
    </ConversionRate>
  </soap:Body>
</soap:Envelope>
Community
  • 1
  • 1
josh
  • 13,793
  • 12
  • 49
  • 58
  • You checked, that it is possible with curl. Why don't you simply try it with HttpClient? At the end each SOAP framework sends/receives XML over the wire. Nothing stops you to implement the SOAP standard on your own. You can even take a look how others did. Most frameworks are open source. – vanje Apr 15 '17 at 20:41

1 Answers1

1

Yes, it is perfectly possible, in fact, under the hood, that's what happens when you call a SOAP based web service _action located at _url URI:

XmlDocument soapEnvelop = new XmlDocument();
    soapEnvelop.LoadXml(@"<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ConversionRate xmlns="http://www.webserviceX.NET/">
      <FromCurrency>USD</FromCurrency>
      <ToCurrency>GBP</ToCurrency>
    </ConversionRate>
  </soap:Body>
</soap:Envelope>");

HttpWebRequest webRequest = CreateWebRequest(_url, _action);
using (Stream stream = webRequest.GetRequestStream())
    {
        soapEnvelopeXml.Save(stream);
    }

Now your request, loaded with your SOAP envelop is ready to be expedited!

rogerwamba
  • 72
  • 2