简体   繁体   中英

Rails: Request to SOAP using Savon: Unable to process request

For learning purposes, I am trying the gem Savon to get information from the GlobalWeather SOAP Webservice. http://www.webservicex.net/globalweather.asmx?WSDL

I am able to connect to the API and retrieve the operations:

[:get_weather, :get_cities_by_country]

But then when I try to make the call passing the message I get this error about the parameter not being passed:

Savon::SOAPFault in CitiesController#index
(soap:Server) System.Web.Services.Protocols.SoapException: Server was unable 
to process request. ---> System.Data.SqlClient.SqlException: Procedure or 
function 'getWCity' expects parameter '@CountryName', which was not 
supplied. at WebServicex.GlobalWeather.GetCitiesByCountry(String 
CountryName) --- End of inner exception stack trace ---

My controller cities code is as follows:

class CitiesController < ApplicationController
  def index
    @operations = client.operations
    @response = client.call(:get_cities_by_country,  message: { CountryName:"Spain" })
  end

  def client
    Savon.client(wsdl: 'http://www.webservicex.net/globalweather.asmx?WSDL')
  end
end

I think the problem might be related to how the hash message gets converted to camelCase according to the docs, so I tried to use the global option convert_request_keys_to :none but nothing different happened.

class CitiesController < ApplicationController
  def index
    @operations = client.operations
    client = client do
      convert_request_keys_to :none 
    end
    @response = client.call(:get_cities_by_country,  message: { CountryName: "Spain" })
  end

  def client
    Savon.client(wsdl: 'http://www.webservicex.net/globalweather.asmx?WSDL')
  end
end

I figure this out, It had to do indeed with convert_request_keys_to option, but it should be passed within the Savon::client call

def client
  Savon.client(wsdl: 'http://www.webservicex.net/globalweather.asmx?WSDL', convert_request_keys_to: :none)
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM