又是用肥皂。我正在尝试使用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> 我所做的就是创建一个头derv。班级
AffHeader < SOAP::Header::SimpleHandler创建了一个UserAuthentification元素。
def initialize
@element = XSD::QName.new(nil, "UserAuthentification")
super(@element)
end并返回一个哈希值
def on_simple_outbound
self.mustunderstand = 1
{ "iId" => ID, "sPassword" => PASSWORD, "sType" => "affiliate" }
end我怎样才能让我的页眉看起来像我想要的那样。例如,我如何添加执行元。
我将继续寻找这个,任何帮助都是非常感谢的。
谢谢
发布于 2009-09-03 13:10:41
在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例如。
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>>https://stackoverflow.com/questions/1358019
复制相似问题