Savon 2 returns nothing in Rails 4

无人久伴 提交于 2019-12-11 21:09:11

问题


Here is my Savon 2

   client = Savon::Client.new(wsdl: "http://www.webservicex.net/uszip.asmx?WSDL")   
   client.operations   
   response = client.call(:get_info_by_zip, :message => { us_zip: "90210" })
   response.to_hash

And response is:

   {:get_info_by_zip_response=>{:@xmlns=>"http://www.webserviceX.NET"}}

In the SoapUI:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET">
   <soapenv:Header/>
   <soapenv:Body>
      <web:GetInfoByZIP>
         <!--Optional:-->
         <web:USZip>90210</web:USZip>
      </web:GetInfoByZIP>
   </soapenv:Body>
</soapenv:Envelope>

I get this response:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <GetInfoByZIPResponse xmlns="http://www.webserviceX.NET">
         <GetInfoByZIPResult>
            <NewDataSet xmlns="">
               <Table>
                  <CITY>Beverly Hills</CITY>
                  <STATE>CA</STATE>
                  <ZIP>90210</ZIP>
                  <AREA_CODE>310</AREA_CODE>
                  <TIME_ZONE>P</TIME_ZONE>
               </Table>
            </NewDataSet>
         </GetInfoByZIPResult>
      </GetInfoByZIPResponse>
   </soap:Body>
</soap:Envelope>

For the life of me I cant figure it out. Can someone please have a look and let me know what am I doing wrong?

Thanks


回答1:


Your tag within the message seems wrong, instead us_zip you should use "USZip" (in quotes!).

This works for me:

#!ruby

require 'savon'
require 'pp'

WSDL_URL = 'http://www.webservicex.net/uszip.asmx?wsdl'

client = Savon.client(
  wsdl: WSDL_URL,
  log: true, # set true to switch on logging
  log_level: :debug,
  pretty_print_xml: true
)

zip = ARGV[0] || "98052"

response = client.call(:get_info_by_zip,
                       message: { "USZip" => zip }
                      )

pp response.to_hash


来源:https://stackoverflow.com/questions/24175909/savon-2-returns-nothing-in-rails-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!