首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ruby soap4r构建头文件

Ruby soap4r构建头文件
EN

Stack Overflow用户
提问于 2009-08-31 15:30:16
回答 1查看 547关注 0票数 0

又是用肥皂。我正在尝试使用soap4r构建一个头文件,应该如下所示

代码语言:javascript
复制
    <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。班级

代码语言:javascript
复制
AffHeader < SOAP::Header::SimpleHandler

创建了一个UserAuthentification元素。

代码语言:javascript
复制
def initialize
     @element = XSD::QName.new(nil, "UserAuthentification")
     super(@element)
   end

并返回一个哈希值

代码语言:javascript
复制
def on_simple_outbound
     self.mustunderstand = 1
     { "iId"  => ID, "sPassword"  => PASSWORD, "sType" => "affiliate" }
end

我怎样才能让我的页眉看起来像我想要的那样。例如,我如何添加执行元。

我将继续寻找这个,任何帮助都是非常感谢的。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-09-03 13:10:41

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

代码语言:javascript
复制
def target_actor= (uri)
  @target_actor = uri
end

在您的on_simple_outbound方法中,您可以使用uri调用target_actor,如下所示:

代码语言:javascript
复制
def on_simple_outbound
   self.mustunderstand = 1
   self.target_actor = "http://api.affiliatewindow.com"
   { "iId"  => ID, "sPassword"  => PASSWORD, "sType" => "affiliate" }
end

例如。

代码语言:javascript
复制
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>>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1358019

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档