Savon 2 在 Rails 4 中什么都不返回 [英] Savon 2 returns nothing in Rails 4

查看:25
本文介绍了Savon 2 在 Rails 4 中什么都不返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Savon 2

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

回应是:

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

在 SoapUI 中:

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>

我收到了这个回复:

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

谢谢

推荐答案

您在消息中的标签似乎有误,您应该使用 us_zip 代替 us_zip(在引号中!).

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

这对我有用:

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

这篇关于Savon 2 在 Rails 4 中什么都不返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆