Savon 2如何向message_tag添加属性

时间:2013-09-09 04:53:01

标签: ruby savon

在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代码?

2 个答案:

答案 0 :(得分:5)

您必须将该属性添加到呼叫中,例如

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

答案 1 :(得分:0)

#!/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>