如何使用 'savon' gem 在 SOAP 请求中指定名称空间?
how to specify namespace in SOAP request with 'savon' gem?
我正在使用 savon
gem 的最新版本并尝试发送 SOAP 请求 我收到有关无效 url 的错误消息:
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>
我不知道我做错了什么,请帮忙。
我注意到 WSDL 文件的第 5820 行位置如下所示:
<soap:address location="{endpoint address}"/>
会不会是问题所在?
已编辑 1。
- 在浏览器中打开:https://partnertest.payback.in/PBExternalServices/v1/soap?wsdl
- 在页面上搜索
{endpoint address}
字符串。
我远不能理解这个特定的 WSDL 文档,但我想知道是否必须有其他东西来代替 {endpoint address}
,比如真正的 URI。例如。 会不会是 WSDL 文档有问题?
已编辑 2
试图删除服务无法识别的 typ
和 typ1
。以 returns 有效响应的工作代码结束:
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
}
}
}
)
我正在使用 savon
gem 的最新版本并尝试发送 SOAP 请求 我收到有关无效 url 的错误消息:
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
<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>
我不知道我做错了什么,请帮忙。
我注意到 WSDL 文件的第 5820 行位置如下所示:
<soap:address location="{endpoint address}"/>
会不会是问题所在?
已编辑 1。
- 在浏览器中打开:https://partnertest.payback.in/PBExternalServices/v1/soap?wsdl
- 在页面上搜索
{endpoint address}
字符串。
我远不能理解这个特定的 WSDL 文档,但我想知道是否必须有其他东西来代替 {endpoint address}
,比如真正的 URI。例如。 会不会是 WSDL 文档有问题?
已编辑 2
试图删除服务无法识别的 typ
和 typ1
。以 returns 有效响应的工作代码结束:
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
}
}
}
)