rails通过肥皂基本认证与savon

时间:2015-02-10 14:44:13

标签: ruby-on-rails ruby soap savon wash-out

我尝试使用savon gem发送基本身份验证的soap请求 我的soap服务器设置为wash_out gem

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

...

当我通过savon向soap服务器发出请求时出现错误:

    @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

在最后一个命令中我收到错误

 Savon::SOAPFault: (Server) Missing required UsernameToken

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

我试过这个并且它有效!

@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

答案 2 :(得分:0)

对于Savon 2.基本授权可以按如下方式进行:

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

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