使用 Savon/Ruby 复制 XML 请求 [英] Replicating XML Request with Savon/Ruby
问题描述
我试图避免使用 Nokogiri/Builder
来构建我的 XML,而是想在 Ruby 2.0.0 中使用 Savon
gem.我有以下请求需要复制:
I am trying to avoid using Nokogiri/Builder
to build my XML and would like to instead use the Savon
gem with Ruby 2.0.0. I have the following request I need to replicate:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetList xmlns="http://tempuri.org/">
<listRequest xmlns:a="http://schemas.datacontract.org/2004/07/Services.List"
i:type="b:NpsListRequest"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:b="http://schemas.datacontract.org/2004/07/Services.List.Strategies">
<a:id>1</a:id>
</listRequest>
</GetList>
</s:Body>
</s:Envelope>
到目前为止,我有这个:
So far I have this:
def soap_client
soap_client = Savon.client(
wsdl: "http://10.10.10.10/ListApi.svc?wsdl"
headers: {"Authorization" => "Basic"},
basic_auth: ['username', 'password'],
env_namespace: :s,
ssl_verify_mode: :none,
log: true,
:pretty_print_xml => true
)
end
然后 soap_client.call :get_list, message: {'id' =>1}
返回这个:
<s:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://tempuri.org/"
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<tns:GetList>
<id>1</id>
</tns:GetList>
</s:Body>
</s:Envelope>
我不知道如何准确复制第一个请求.tns:
上的 GetList
命名空间是错误的,我也无法复制 <listRequest xmlns:a =
部分.关于如何在 Savon 中执行此操作有任何想法吗?
I can't figure out how to replicate the first request exactly. the tns:
namespace on GetList
is wrong, and I can't replicate the <listRequest xmlns:a =
piece either. Any thoughts on how to do this within Savon?
推荐答案
GetList 上的命名空间是正确的.你可能需要写的是
The namespace on GetList is correct. What you probably need to write is
soap_client.call(:get_list,
:attributes => {'xmlns:b'=>'http://schemas.datacontract.org/'},
message: { 'ListRequest' => { 'tns:id' => 1 } }
这不是您问题的确切解决方案,因为我无法访问您的 wsdl,也无法进行测试.但你应该得到解决方案的关键.
That won't be the exact solution for your problem, because I don't have access to your wsdl and can't test. But you should get the key to a solution.
这篇关于使用 Savon/Ruby 复制 XML 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!