質問

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>

ご協力ありがとうございます。

役に立ちましたか?

解決

soap4rはあまりきれいではありません。私はrdocs abitをいじってみましたが、問題を解決する最も簡単な方法は、 on_simple_outbound が作成したい要素の文字列表現を返すことです。

soの代わりに

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 は面白そうです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top