本文介绍了无法在 savon 调用上设置 SOAP 标头参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 savon 2.2 进行 SOAP 调用.

I'm using savon 2.2 for making SOAP calls.

初始化:

  client = Savon.client(
  wsdl: SOAP_WSDL,
  endpoint: SOAP_URL)

我可以像这样进行 SOAP 调用,而且工作正常:

I can make a SOAP call like this and it works fine:

resp =  client.call(:login, message: { username: SOAP_USER, password: SOAP_PASSWORD })

现在我需要进行另一个调用,它需要在 SOAP 标头中设置一些参数.从 savorb.com 上的文档中,我发现我应该使用请求方法:

Now I need to make another call which requires setting some parameters in the SOAP header. From the documentation on savorb.com I found I should use the request method:

 response = client.request :get_user_info do
    soap.header = { :session_id => sid }
 end 

但是我收到一个错误,说请求方法不存在:

But I'm getting an error saying that the request method does not exist:

undefined method `request' for #<Savon::Client:0x007f1560f80490>

我有不同版本的 savon 还是什么?我尝试使用呼叫"而不是请求",但后来我得到了:

Do I have a different version of savon or what?? I tried using "call" instead of "request" but then I'm getting:

ArgumentError - wrong number of arguments (1 for 2):
gem) savon-2.2.0/lib/savon/options.rb:35:in `method_missing'
(gem) savon-2.2.0/lib/savon/block_interface.rb:20:in `method_missing'
app/models/tool.rb:23:in `block in doUpload'

推荐答案

您使用的是 Savon 2.2.0.你应该使用

You're on Savon 2.2.0.You should use

response = client.call(:get_user_info, :soap_header => { :session_id => sid })

'request' 是 1.x 版本中的一个方法,不再受支持.

'request' is a method from version 1.x and not supported anymore.

这篇关于无法在 savon 调用上设置 SOAP 标头参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 08:37