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,
This is a problem with the way Savon handles Namespaces. See this answer Why is "wsdl" namespace interjected into action name when using savon for ruby soap communication?
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
You might find the latest gem uses the method "request" followed by the symbol reference to the method required.
require 'rubygems'
require 'savon'
client = Savon::Client.new "http://www.webservicex.net/stockquote.asmx?WSDL"
client.request :get_quote do |soap|
soap.input = [
"GetQuote",
{ "xmlns" => "http://www.webserviceX.NET/" }
]
soap.body = {:symbol => "AAPL"}
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With