cannot set SOAP header parameters on savon call

不羁的心 提交于 2019-12-06 02:57:45

问题


I'm using savon 2.2 for making SOAP calls.

Initialize:

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

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

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

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>

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'

回答1:


You're on Savon 2.2.0. You should use

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

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




回答2:


What if you create a new Savon client with the session id?

client = Savon.client(
  wsdl: SOAP_WSDL,
  endpoint: SOAP_URL,
  soap_header: {
    "Header" => { "session_id" => sid }
  }
)

client.call(:get_user_info, message: data)



回答3:


Or like this, for both a header and body:

@response = @client.call(operation, { :message => message, :soap_header => header })


来源:https://stackoverflow.com/questions/18466054/cannot-set-soap-header-parameters-on-savon-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!