【问题标题】:Savon/Ruby - Unable to add ':info' to specific XML tagSavon/Ruby - 无法将 ':info' 添加到特定的 XML 标记
【发布时间】:2017-12-07 09:34:06
【问题描述】:

我目前正在尝试在 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>

我已经编写了以下代码来创建该肥皂调用:

   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:。

谢谢!

【问题讨论】:

    标签: ruby xml soap savon


    【解决方案1】:

    通过使用字符串插值修复它:

        $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'})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-30
      • 2015-02-03
      相关资源
      最近更新 更多