Note that there are some explanatory texts on larger screens.

plurals
  1. POForce rebuild the SOAP-Header after authenticating
    text
    copied!<p>My SOAP-Server expects every request to have a valid token in the soap-header to authenticate the soap-client. This token is only valid for a certain period of time, so I have to expect it to be invalid in every call.</p> <p>I am trying to find a way to force savon to rebuild the SOAP-Header (i.e. use the new auth-token) after I (re)authenticate with the SOAP-Server. I am not sure, if that is either a savon problem or a ruby one. Here is what I have so far.</p> <pre><code>class Soapservice extend Savon::Model # load stored auth-token @@header_data = YAML.load_file "settings.yaml" client wsdl: 'locally-cached-wsdl.xml', soap_header: {'verifyingToken' =&gt; @@header_data} operations :get_authentification_token, :get_server_time # request a new auth-token and store it def get_authentification_token response = super(:message =&gt; { 'oLogin' =&gt; { 'Username' =&gt; 'username', 'Userpass' =&gt; 'password' } }) settings = { 'UserID' =&gt; response[:user_id].to_i, 'Token' =&gt; response[:token], } File.open("settings.yaml", "w") do |file| file.write settings.to_yaml end @@header_data = settings end def get_server_time return super() rescue Savon::SOAPFault =&gt; error fault_code = error.to_hash[:fault][:faultstring] if fault_code == 'Unauthorized Request - Invalide Token' get_authentification_token retry end end end </code></pre> <p>When I call</p> <pre><code>webservice = Soapservice.new webservice.get_server_time </code></pre> <p>with an invalid Token, it reauthenticates and saves the new Token successfully, but the <code>retry</code> doesn't load the new header (the result is an infinite loop). Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload