2009-03-10 9 views
3

soap4rで作業していて、SOAP :: Header :: SimpleHandlerを使用しようとしましたが、送信メッセージにカスタムヘッダーを挿入しようとしていますが、うまくいかないそれは属性を含めるのではなくサブ要素としてして取得する方法:返すsoap4rカスタムヘッダー

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> 

何か助けていただければ幸いです。

答えて

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

を試してみてください、あなたはそれがより多くのrubyishを見えるように、それを試みることができます。

もう1つのオプションは、新しいSOAPライブラリを調べることです。 handsoapが面白そうです。

関連する問題