Ruby on rails Ruby soap4r构建头

Ruby on rails Ruby soap4r构建头,ruby-on-rails,ruby,Ruby On Rails,Ruby,又是肥皂。 我正在尝试使用soap4r构建一个标题,应该是这样的 <SOAP-ENV:Header> <ns1:UserAuthentication SOAP-ENV:mustUnderstand="1" SOAP-ENV:actor="http://api.affiliatewindow.com"> <ns1:iId>*****</ns1:iId> <ns1:sPassword>*****</ns1:sPa

又是肥皂。 我正在尝试使用soap4r构建一个标题,应该是这样的

    <SOAP-ENV:Header> 
<ns1:UserAuthentication  
SOAP-ENV:mustUnderstand="1"  
SOAP-ENV:actor="http://api.affiliatewindow.com"> 
<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">true</ns1:getQuota> 
</SOAP-ENV:Header> 
然后返回一个散列

def on_simple_outbound
     self.mustunderstand = 1
     { "iId"  => ID, "sPassword"  => PASSWORD, "sType" => "affiliate" }
end
如何使我的标题看起来更像我想要的。例如,如何添加演员

我会继续搜索,非常感谢您的帮助


谢谢

在SOAP4R中,target_actor属性是只读的,但您可以添加一个新方法,如:

def target_actor= (uri)
  @target_actor = uri
end
在on_simple_outbound方法中,您可以使用uri调用target_actor,如下所示:

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


谢谢演员补充道,一切都很好。我可能不得不换成手拖,因为我看到它能让你更好地控制。soap4r很好,但在某些情况下,由于缺乏经验而很难控制某些关键要素的事实会让你大吃一惊。。
def target_actor= (uri)
  @target_actor = uri
end
def on_simple_outbound
   self.mustunderstand = 1
   self.target_actor = "http://api.affiliatewindow.com"
   { "iId"  => ID, "sPassword"  => PASSWORD, "sType" => "affiliate" }
end
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>>