ruby - soap4r 自定义 header

标签 ruby documentum soap4r documentum-dfs

我一直在使用 soap4r 并尝试使用 SOAP::Header::SimpleHandler,我试图让它在传出消息上放置自定义 header ,但我不知道如何获取它包括属性而不是作为子元素:

    class ServiceContext < SOAP::Header::SimpleHandler
  NAMESPACE = "http://context.core.datamodel.fs.documentum.emc.com/"
  def initialize()
    super(XSD::QName.new(NAMESPACE, 'ServiceContext'))
    XSD::QName.new(nil, "Identities")
  end

  def on_simple_outbound
    username = "username"
    password = "password"
    docbase = "Test"
    return {"Identities" => {"Username" => username, "Password" => password, "Docbase" => docbase}}
  end
end

返回:

    <n1:ServiceContext xmlns:n1="http://context.core.datamodel.fs.documentum.emc.com/"
        env:mustUnderstand="0">
      <n1:Identities>
        <n1:Username>username</n1:Username>
        <n1:Password>password</n1:Password>
        <n1:Docbase>Test</n1:Docbase>
      </n1:Identities>
    </n1:ServiceContext>

我需要它返回的是以下内容:

    <ServiceContext xmlns="http://context.core.datamodel.fs.documentum.emc.com/">
        <Identities xsi:type="RepositoryIdentity" userName="_USER_" password="_PWD_" repositoryName="_DOCBASE_" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    </ServiceContext>

非常感谢任何帮助。

最佳答案

soap4r 不是很漂亮。我仔细查看了 rdocs abit,看起来解决问题的最简单方法是让 on_simple_outbound 返回您要创建的元素的字符串表示形式。

所以而不是

return {"Identities" => {"Username" => username, "Password" => password, "Docbase" => docbase}}

尝试

%Q(<Identities xsi:type="RepositoryIdentity" userName="#{user}" password="#{password}" repositoryName="#{docbase}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>)

使用像 builder 这样的东西,你可以让它看起来更 ruby 色,但试试吧。

另一种选择是研究较新的 soap 库。 handsoap看起来很有趣。

关于ruby - soap4r 自定义 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/630050/

相关文章:

ruby - 将 setter 与 instance_variable_set 一起使用

ruby-on-rails - ruby on rails 中的 Payflow 支付集成

ruby - 模块类 << 自常量

DQL-Documentum 查询

ruby - 使用 soap4r 访问 SOAP 服务无法访问返回对象的内容

ruby - 从 Ruby 成功调用 WCF 服务?任何人?

Ruby 行编辑 telnet 服务器

java - 如何使用httpclient 4.3.6调用DCTM 7.1 REST API?

ruby - 方法名为 "type"的 Web 服务。如何使用 ruby 消费它?

D2 安装后出现 java.lang.ClassCastException