如何使用' savon'在SOAP请求中指定命名空间宝石?

时间:2015-01-05 06:58:19

标签: ruby soap rubygems savon

我正在使用最新版本的savon gem并尝试发送SOAP请求我收到有关无效网址的错误:

 Invalid URL: %7Bendpoint%20address%7D (ArgumentError)
        from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/httpi-2.3.0/lib/httpi/request.rb:27:in `url='
        from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/savon-2.8.0/lib/savon/operation.rb:103:in `build_request'
        from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/savon-2.8.0/lib/savon/operation.rb:51:in `call'
        from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/savon-2.8.0/lib/savon/client.rb:36:in `call'

我的代码是:

require "savon"
require "excon"

Excon.defaults[:ssl_verify_peer] = false

class Payback

  attr_reader :connection, :client, :operation, :message

  SOAP_URL = "https://partnertest.payback.in/PBExternalServices/v1/soap?wsdl"

  def initialize operation, message
    @client = Savon.client(wsdl: "https://partnertest.payback.in/PBExternalServices/v1/soap?wsdl", ssl_verify_mode: :none)
    @operation = operation
    @message = message
  end

  def response
    @response ||= client.call(operation, message: message)
  end

end

这就是我使用它的方式。(我知道命名空间有问题

payback = Payback.new :get_account_balance,
                      {"typ:Authentication" => { "typ1:Principal" => { "typ1:PrincipalValue" => 9899012182,
                                                                       "typ1:PrincipalClassifier" => 3 }}}
payback.response

我需要使用savon

构建此XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://www.payback.net/lmsglobal/ws/v1/extint/types" xmlns:typ1="http://www.payback.net/lmsglobal/xsd/v1/types">
   <soapenv:Header/>
   <soapenv:Body>
      <typ:GetAccountBalanceRequest>
         <typ:Authentication>
            <typ1:Principal>
               <typ1:PrincipalValue>9899012182</typ1:PrincipalValue>
               <typ1:PrincipalClassifier>3</typ1:PrincipalClassifier>
            </typ1:Principal>
         </typ:Authentication>
      </typ:GetAccountBalanceRequest>
   </soapenv:Body>
</soapenv:Envelope>

我不知道我在这里做错了什么,请帮忙。

1 个答案:

答案 0 :(得分:1)

我注意到在WSDL文件的第5820行,该位置如下所示:

<soap:address location="{endpoint address}"/>

可能是问题吗?

已编辑1

  1. 在浏览器中打开:https://partnertest.payback.in/PBExternalServices/v1/soap?wsdl
  2. 在页面上搜索{endpoint address}字符串。
  3. 我远没有理解这个特定的WSDL文档,但我想知道是否必须有其他代替{endpoint address}的东西,就像真正的URI一样。例如。 可能是有问题的WSDL文档

    已编辑2

    尝试删除服务无法识别的typtyp1。结束了返回有效响应的工作代码:

    puts Savon.client(
      wsdl: 'https://partnertest.payback.in/PBExternalServices/v1/soap?wsdl',
      endpoint: 'https://partnertest.payback.in/PBExternalServices/v1/soap',
      ssl_verify_mode: :none
    ).call(
      :get_account_balance,
      :message => {
        'Authentication' => {
          'Principal' => {
            'PrincipalValue' => 9899012182,
            'PrincipalClassifier' => 3
          }
        }
      }
    )