我目前正在尝试在Ruby中运行Soap Call。使用Savon客户端,我没有得到我想要的响应。这是我想要创建的XML:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sch="http://test.com/requests/test-manager/schema">
<soapenv:Header/>
<soapenv:Body>
<sch:createTestDateRequest>
<sch:testMethod>DD</sch:testMethod>
<sch:testPeriodNumber>999</sch:testPeriodNumber>
<sch:testDateTime>2017-12-14 00:00:00</sch:testDateTime>
<sch:name>Automated test</sch:name>
</sch:createTestDateRequest>
</soapenv:Body>
</soapenv:Envelope>
我已经编写了以下代码来创建Soap Call:
require 'savon'
$soap_client_testmgr = Savon.client(
wsdl: 'http://test.com/test-manager-ws/TestManagerSoapService?wsdl',
namespace: 'http://test.com/requests/test-manager/schema',
env_namespace: :soapenv,
namespace_identifier: :sch,
pretty_print_xml: true,
log: true,
log_level: :debug)
$soap_client_testmgr.call(:create_test_date, message: {
:testMethod => 'DD',
:testPeriodNumber => $test_period,
:testDateTime => (Date.today+7).strftime('%Y-%m-%d') + ' 00:00:00',
:name => 'Automated test'})
但生成的XML如下所示,在每个单独的名称标记之前缺少:sch。这应该从WSDL中获取,对吗?我已经查看了命名空间标识符,但我还没有找到合适的解决方案。
<soapenv:Body>
<sch:createTestDateRequest>
<testMethod>DD</testMethod>
<testPeriodNumber>999</testPeriodNumber>
<testDateTime>2017-12-14 00:00:00</testDateTime>
<name>Automated test</name>
</sch:createTestDateRequest>
</soapenv:Body>
</soapenv:Envelope>
有什么可以解决这个问题?我只需要在名称标签之前添加sch:
谢谢!
答案 0 :(得分:0)
使用字符串插值修正了它:
$soap_client_testmgr.call(:create_test_date, message: {
:"sch:testMethod" => 'DD',
:"sch:testPeriodNumber" => $test_period,
:"sch:testDateTime" => (Date.today+7).strftime('%Y-%m-%d') + ' 00:00:00',
:"sch:name" => 'Automated test'})