Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby/Savon: Having trouble with namespace for a soap request

Tags:

soap

ruby

savon

I'm having trouble changing the namespace for the SOAP xml I'm building. I'm not sure how to change "xmlns:env=" to "xmlns:soapenv=" and "xmlns:tns=" to "xmlns:web="

What I'm trying to build:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:web="http://www.webserviceX.NET/">
    <soapenv:Header/>
    <soapenv:Body>
         <web:ConvertTemp>
             <web:Temperature>100</web:Temperature>
             <web:FromUnit>degreeCelsius</web:FromUnit>
             <web:ToUnit>degreeFahrenheit</web:ToUnit>
         </web:ConvertTemp>
    </soapenv:Body>
</soapenv:Envelope>

What I'm currently getting

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://www.webserviceX.NET/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <env:Body>
      <tns:ConvertTemp>
         <tns:temperature>100</tns:temperature>
         <tns:fromUnit>degreeCelsius</tns:fromUnit>
         <tns:toUnit>degreeFahrenheit</tns:toUnit>
      </tns:ConvertTemp>
   </env:Body>
</env:Envelope>

My code:

client = Savon.client(wsdl: "http://www.webservicex.net/ConvertTemperature.asmx?WSDL")
message = { temperature: '100',FromUnit: 'degreeCelsius' , ToUnit: 'degreeFahrenheit'}
response = client.call(:convert_temp, message: message)

Thanks for the help.

like image 810
Travis Frazier Avatar asked Oct 01 '13 14:10

Travis Frazier


1 Answers

I was able to figure out how to change those. If anybody is interested the way to change those is:

client = Savon.client(env_namespace: :soapenv,namespace_identifier: :web)

That wasn't actually causing my problem though. Turns out that my fields were getting camelcased without me noticing. "FromUnit" became "fromUnit".

like image 177
Travis Frazier Avatar answered Nov 14 '22 02:11

Travis Frazier