Savon 2在Rails 4中没有返回任何内容

时间:2014-06-12 03:13:31

标签: ruby soap wsdl soapui savon

这是我的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

响应是:

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

在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>

我收到了这个回复:

<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>

对于我的生活,我无法弄明白。有人可以看看,让我知道我做错了什么?

由于

1 个答案:

答案 0 :(得分:1)

您在邮件中的标记似乎有误,而是us_zip您应该使用“USZip”(在引号中!)。

这对我有用:

#!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