views:

166

answers:

1

Hi,

Again with the soap. I am trying to build a header using soap4r that is supposed to look like this

    <SOAP-ENV:Header> 
<ns1:UserAuthentication  
SOAP-ENV:mustUnderstand="1"  
SOAP-ENV:actor="http://api.affiliatewindow.com"&gt; 
<ns1:iId>*****</ns1:iId> 
<ns1:sPassword>*****</ns1:sPassword> 
<ns1:sType>affiliate</ ns1:sType> 
</ns1:UserAuthentication> 

<ns1:getQuota SOAP-ENV:mustUnderstand="1" SOAP- 
ENV:actor="http://api.affiliatewindow.com"&gt;true&lt;/ns1:getQuota&gt; 
</SOAP-ENV:Header>

What I have done is created a header derv. class

AffHeader < SOAP::Header::SimpleHandler

Created a UserAuthentification element.

def initialize
     @element = XSD::QName.new(nil, "UserAuthentification")
     super(@element)
   end

And return a hash

def on_simple_outbound
     self.mustunderstand = 1
     { "iId"  => ID, "sPassword"  => PASSWORD, "sType" => "affiliate" }
end

How can I make my header look like I want further. How do I add the actor for example.

I am going to keep searching on this, any Help is very appreciated.

Thank you

A: 

In SOAP4R, the target_actor attribute is read only but you can add a new method like:

def target_actor= (uri)
  @target_actor = uri
end

and in your on_simple_outbound method, you can call target_actor with your uri like so:

def on_simple_outbound
   self.mustunderstand = 1
   self.target_actor = "http://api.affiliatewindow.com"
   { "iId"  => ID, "sPassword"  => PASSWORD, "sType" => "affiliate" }
end

E.g.

irb(main):003:0> h = AffHeader.new
=> #<AffHeader:0x3409ef0 @target_actor=nil, @encodingstyle=nil, 
@element=#<XSD::QName:0x1a04f5a {}UserAuthentification>,
@mustunderstand=false, @elename=#<XSD::QName:0x1a04f5a {}UserAuthentification>>

irb(main):006:0> h.on_simple_outbound
=> {"sType"=>"affiliate", "sPassword"=>"secret", "iId"=>"johndoe"}

irb(main):007:0> h
=> #<AffHeader:0x3409ef0 @target_actor="http://api.affiliatewindow.com",
@encodingstyle=nil, 
@element=#<XSD::QName:0x1a04f5a {}UserAuthentification>, 
@mustunderstand=1, @elename=#<XSD::QName:0x1a04f5a 
{}UserAuthentification>>
Philippe Monnet
Thanks! It added the actor and everything is fine. I just have to switch to handsoap probably, since I saw it gives you a better control. soap4r is very ok, but in some cases the fact that it s hard to get control over some key elements due the lack of experience can give you a headake..