0

I'm trying to send soap request with basic authentication with savon gem
My soap server is set up with wash_out gem

class OrdersController < ApplicationController  
     soap_service namespace: 'sir:WashOut', wsse_username: SIRA[:auth][:username], wsse_password: SIRA[:auth][:password]  

....

When i make a request to soap server via savon i get an error:

    @client = Savon.client(
      wsdl:  "http://localhost:3000/orders/wsdl",
      soap_header: { 'Username' =>SIRA[:auth][:username], 'Password' => SIRA[:auth][:password] }
    )  

  @response = @client.call(:notify ).to_hash

On the last command i get an error

 Savon::SOAPFault: (Server) Missing required UsernameToken
Elmor
  • 4,775
  • 6
  • 38
  • 70

3 Answers3

3
client = Savon.client(
           wsdl: 'http://service.example.com?wsdl',
    soap_header: { 
                 "AuthenticateRequest" => 
                                {"apiKey" => "****** your api *********"}}, 
    pretty_print_xml: true)

client.operations

response = client.call(:function)

Note: "apiKey" is my prams to authenticate, your can be different
Steffen Roller
  • 3,464
  • 25
  • 43
Mukesh
  • 921
  • 10
  • 23
0

I've tried this and it works!

@client = Savon.client(
  wsdl:  "http://localhost:3000/orders/wsdl",
  wsse_auth: [SIRENA[:auth][:username], SIRENA[:auth][:password] ],
  logger: Rails.logger
)

 @response = @client.call(:notify,  ).to_hash
Elmor
  • 4,775
  • 6
  • 38
  • 70
0

For Savon 2. Basic authorization can be done as follows:

@client = Savon.client(
  wsdl: "http://localhost:3000/orders/wsdl",
  basic_auth: ["username", "password"]
)  

@response = @client.call(:notify ).to_hash
Abhi
  • 4,123
  • 6
  • 45
  • 77