Search code examples
rubyxmlsoapwsdlsavon

Case problem in SOAP message tag names using savon


I'm using Ruby 1.9.2 with savon 0.9.2 on Windows 7 Professional 64 bit.

I need to call a web SOAP service that requires a security token that I get from a second web SOAP service. The code I use is as follows:

require 'savon'

client = Savon::Client.new "http://some.url?wsdl"
client.wsdl.soap_actions

start_session_response = client.request :start_session do
  soap.input = ["StartSession", {:xmlns => "http://some.schema" } ]
  soap.body = { :userName => "User", :password => "password" }
end

do_something_response = client.request :do_something do
  soap.input = [ "DoSomething", { :xmlns => "http://some.schema"} ]
  soap.body = { :securityToken => start_session_response.to_hash[:start_session_response][:security_token] }
end

This results in XML that looks like:

<?xml version="1.0" encoding="utf-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="http://some.schema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <DoSomething xmlns="http://some.schema">
      <wsdl:securityToken>
        <wsdl:tokenType>sessiontoken</wsdl:tokenType>
        <wsdl:token>
         .
        .
        .
        </wsdl:token>
      </wsdl:securityToken>
    </DoSomething>
  </env:Body>
</env:Envelope>

Never mind the weird namespace convention (or is that just me) in this XML that is savon doing its thing.

The problem I face is that the tags inside the securitytoken tag all start with a lower case letter where they should be upper case. So <tokenType> and <token> should have been <TokenType> and <Token>.

In my opinion the definition of these tags are all in the WSDL that is used to create the savon client. That definition seems not to be used or used incorrectly.

What can I do to get the correct XML/SOAP message from savon?


Solution

  • Savon uses Gyoku for the conversion of tags I believe. To change the symbol conversion you can insert the following statement:

    Gyoku.convert_symbols_to :camelcase # or one of [:none, :lover_camelcase]
    

    hope that helps.