soap4r自定义标头

时间:2009-03-10 13:02:43

标签: ruby documentum soap4r documentum-dfs

我一直在使用soap4r并尝试使用SOAP :: Header :: SimpleHandler,我试图让它在传出消息上放置自定义标头,但我无法弄清楚如何获取它包含属性而不是子元素:

    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>

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

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"/>)

使用类似构建器的东西,你可以让它看起来更像红宝石,但试试吧。

另一种选择是调查较新的肥皂库。 handsoap看起来很有趣。

相关问题