【问题标题】:Savon 2 how to add attribute to message_tagSavon 2 如何将属性添加到 message_tag
【发布时间】:2013-09-10 21:43:55
【问题描述】:

在 Savon 1 中,我可以使用 soap.input 来添加 xmlns,如下所示:

soap_client = Savon.client("http://pathtowsdl.com/a.svc?wsdl")

response = soap_client.request "AnAction" do
  http.headers["soapAction"] = "AnAction"
  soap.input = ["AnAction", {"xmlns" => "http://apathtosomething.com"}]
  soap.body = {
    "SomeAttribute" => "SomeValue"
  }
end

在 Savon 2 中,我可以做到 client.call(:authenticate, message_tag: :authenticationRequest) 但是如何将xmlns 添加到authenticationRequest 标签中?

【问题讨论】:

  • 当前的 xml 输出是什么,你希望它是什么?
  • 当前:,预期:xyz">

标签: ruby savon


【解决方案1】:

您必须将属性添加到调用中,例如。

client.call('CreateRequest', :attributes => { 'xmlns' => 'xyz' })

【讨论】:

    【解决方案2】:
    #!/usr/bin/env ruby
    
    require 'savon'
    
    soap_client = Savon.client( endpoint: 'http://example.com',
                                namespace: 'http://v1.example.com')
    soap_client.call(:authenticate, 
                     message_tag: :authenticationRequest, 
                     :attributes => { "xmlns" => "http://apathtosomething.com" })
    

    输出

    <?xml version="1.0" encoding="UTF-8"?>
    <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:wsdl="http://v1.example.com"
                  xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
      <env:Body>
        <wsdl:authenticationRequest xmlns="http://apathtosomething.com">
        </wsdl:authenticationRequest>
      </env:Body>
    </env:Envelope>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-18
      • 1970-01-01
      • 1970-01-01
      • 2019-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多