tags:

views:

133

answers:

1

I'm trying to use ruby and Savon to consume a web service.

The test service is http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2

require 'rubygems'
require 'savon'

client = Savon::Client.new "http://www.webservicex.net/stockquote.asmx?WSDL"
client.get_quote do |soap| 
  soap.body = {:symbol => "AAPL"} 
end

Which returns an SOAP exception. Inspecting the soap envelope, it looks to me that the soap request doesn't have the correct namespace(s).

Can anyone suggest what I can do to make this work? I have the same problem with other web service endpoints as well.

Thanks,

+1  A: 

This is a problem with the way Savon handles Namespaces. See this answer http://stackoverflow.com/questions/2294325/why-is-wsdl-namespace-interjected-into-action-name-when-using-savon-for-ruby-so

You can resolve this by specifically calling soap.input and passing it an array, the first element is the method and the second is a hash containing the namespace(s)

require 'rubygems'
require 'savon'

client = Savon::Client.new "http://www.webservicex.net/stockquote.asmx?WSDL"
client.get_quote do |soap| 
  soap.input = [ 
    "GetQuote", 
    { "xmlns" => "http://www.webserviceX.NET/" } 
  ]
  soap.body = {:symbol => "AAPL"} 
end
Steve Weet