ruby - 你如何处理 Savon 中的嵌套命名空间?

标签 ruby xml ruby-on-rails-3 soap savon

如果我有以下 SOAP 请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://test.org/" xmlns:hon="http://schemas.datacontract.org/2004/07/TEST.RVU.Entity">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:Authenticate>
         <!--Optional:-->
         <tem:authenticationDet>
            <!--Optional:-->
            <hon:AccountType>0</hon:AccountType>
            <!--Optional:-->
            <hon:Password>bacon</hon:Password>
            <!--Optional:-->
            <hon:UserName>smith</hon:UserName>
         </tem:authenticationDet>
      </tem:Authenticate>
   </soapenv:Body>
</soapenv:Envelope>

如何使用包含 tem: 和 hon: 命名空间的 Savon gem 写下有效的 soap 请求?

谢谢

最佳答案

您需要设置额外的命名空间。

脚本可能如下所示:

#!ruby

require "savon"

Savon.configure do |c|
  c.pretty_print_xml = true
  c.env_namespace = :soapenv
end

client = Savon::Client.new do
  wsdl.namespace = "http://test.org"
  wsdl.endpoint = "http://www.your-real-endpoint.com"
end

resp = client.request :tem, 'Authenticate' do
  soap.namespaces["xmlns:hon"] = "http://schemas.datacontract.org/2004/08/TEST.RVU.Entity"
  soap.body = { "tem:authenticationDet" => 
                { "hon:AccountType" => 0,
                  "hon:Password" => "bacon",
                  "hon:UserName" => "smith" }
              }
end

关于ruby - 你如何处理 Savon 中的嵌套命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12913527/

相关文章:

mysql - Ruby on Rails 安装 - Ubuntu 15

ruby-on-rails-3 - 基于现有模型的 Rails Scaffold 不起作用

ruby - 如何确定 Ruby 脚本的 shell 执行上下文?

ruby-on-rails - Apache Tomcat 和 ruby

xml - RSS 提要 : how to recommend an update interval?

php - 解析 XML 太慢?

ruby - Rails 模型中 around_create 回调的目的是什么?

ruby - 如何对父类(super class)隐藏方法?

涉及 utc 的 Ruby 时间操作

c# - 有没有办法用 OpenXML 库了解 MS word 分页?