I am trying to send a soap request to an open webservice (webserviceX.NET currency converter). Here is my code:
String SOAP_REQUEST = "<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>EUR</FromCurrency><ToCurrency>ILS</ToCurrency></SOAP:Body></SOAP:Envelope>";
// SOAPEnvelope env = new SOAPEnvelope();
//Create a Stream Source of the Request String
byte[] reqBytes = SOAP_REQUEST.getBytes();
ByteArrayInputStream bis = new ByteArrayInputStream(reqBytes);
StreamSource ss = new StreamSource(bis);
//Create a SOAP Message Object
MessageFactoryImpl messageFactory = new MessageFactoryImpl();
SOAPMessage msg = messageFactory.createMessage();
SOAPPart soapPart = msg.getSOAPPart();
//Set the soapPart Content with the stream source
soapPart.setContent(ss);
//Create a WebService Call
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setProperty( Call.SOAPACTION_USE_PROPERTY, new Boolean( true ) );
call.setProperty( Call.SOAPACTION_URI_PROPERTY, "http://www.webserviceX.NET/ConversionRate");
call.setEncodingStyle("utf-8");
//Invoke the WebService.
SOAPEnvelope resp = call.invoke(((org.apache.axis.SOAPPart)soapPart).getAsSOAPEnvelope());
...
//then i parse the resulting SOAPEnvelope get the value.
here in this url, you can see the nature of the soap request and response when interacting with this webservice..
http://www.webservicex.net/CurrencyConvertor.asmx?op=ConversionRate
my java code above, get the right and exact soap response specified in the URL I provided and expected.. but always with the value I need as 0.
This is the soap response I get:
<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><ConversionRateResponse
xmlns="http://www.webserviceX.NET/">
<ConversionRateResult>0</ConversionRateResult></ConversionRateResponse>
</soap:Body></soap:Envelope>
You can see the CoversionRateResult as 0, although it should return 4.69. I tried another webservice they provide and I get aways such result.
Can someone please help me by looking what could be missing in my java code? I tried different variations and keep playing around since a day 🙁 .. and nothing.
I would really appreciate anyone help me in this.
Thank you,
The correct string passed in my above example, which worked is:
Just in case anyone encountered this issue.. my reputation does not allow me to mark it as correct.
And many thanks to mcfinnigan for helping me out..