[英]Rails: Request to SOAP using Savon: Unable to process request
出於學習目的,我嘗試使用Savon來從GlobalWeather SOAP Web服務獲取信息。 http://www.webservicex.net/globalweather.asmx?WSDL
我能夠連接到API並檢索操作:
[:get_weather, :get_cities_by_country]
但是然后當我嘗試通過消息傳遞呼叫時,出現有關未傳遞參數的錯誤:
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 ---
我的控制器城市代碼如下:
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
我認為問題可能與根據文檔將哈希消息如何轉換為camelCase有關,因此我嘗試使用全局選項convert_request_keys_to:none,但沒有發生任何不同的情況。
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
我弄清楚了,它確實與convert_request_keys_to選項有關,但是應該在Savon :: client調用中傳遞它
def client
Savon.client(wsdl: 'http://www.webservicex.net/globalweather.asmx?WSDL', convert_request_keys_to: :none)
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.