Unable to set SOAP header parameters for calling savon

I am using savon 2.2 to invoke SOAP.

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 that requires setting some parameters in the SOAP header. From the documentation on savorb.com, I found that I should use the request method:

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

But I get a message that the request method does not exist:

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

Do I have another version of Savona or what? I tried using "call" instead of "request", but then I get:

 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' 
+4
source share
3 answers

You are on Savon 2.2.0. You have to use

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

'request' is a version 1.x method and is no longer supported.

+7
source

What if you create a new Savon client with a session ID?

 client = Savon.client( wsdl: SOAP_WSDL, endpoint: SOAP_URL, soap_header: { "Header" => { "session_id" => sid } } ) client.call(:get_user_info, message: data) 
0
source

Or like this, for both the headline and body:

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

Source: https://habr.com/ru/post/1499142/


All Articles