Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
soap4r authentication problem
5 Posts
soap4r authentication problem

class SendBasicAuthenticationFilter < SOAP::Filter::StreamHandler

  def initialize(username, password)
    @authorization = 'Basic ' + [username + ':' + password].pack('m').delete("\r\n")
  end

  def on_http_outbound(request)
    request.header.delete('Authorization')
    request.header['Authorization'] = @authorization
  end

  def on_http_inbound(request, response)
  end

end

then

@driver = YourSoapDriver.new
@driver.streamhandler.filterchain &lt;&lt;
          SendBasicAuthenticationFilter.new(username, password)

(where YourSoapDriver is a class of ::SOAP::RPC::Driver) ...

hello, I had used the rpc soap in order to consume the webservice, i had written a function the application controller where i had created the soap object passing the wsdl link and the urn def load_rpc_driver(url,urn_service)

require 'soap/rpc/driver'
url_link = url
urn = urn_service
@driver = SOAP::RPC::Driver.new(url_link, urn)    

end

in the user controller where i am calling the load_rpc_driver creating the soap client, the wsdl i am using is created in php so it is there where the password and username handled so i am not sure how about passing the username and password or i guess you can create your soap client with the above method and use the second line in your code to pass the user name and password.

                                                                                                                                                                                       rashmi

Hi Ahmed,

I'm not sure but you can check with following syntax...

soap_client = SOAP::RPC::Driver.new(wsdl, urn_webservice)

and probably then provide the username and passowrd for the authentication.

Good Luck.. :)

  • Ganesh K.
Person
Jruby, Ruby, Rails Programmer
Sign In To Rate Post

I know this isn't as helpful as a direct answer to your problem, but when I got tired of hassling with the mess that is soap4r I switched to handsoap (http://github.com/unwire/handsoap). It doesn't do quite as much "for" you, but it turns out that's a good thing. The documentation is great, and I've really enjoyed working with it. Worth looking at if you're stuck on Soap4r.

Hi, I'm writing a soap client to read the WSDL file. But the file is on HTTPS and on a protected page. I'm able to login and view using my web browser but when I access in my client using following code I get error.

soap_client = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver soap_client.options["protocol.http.basic_auth"] << [wsdl,user,pass]

I get error on the first line and it doesn't go to the 2nd line to read the username and password, unexpected response: #....

Anyway to work around? I have worked in PHP and in PHP soap client takes username and password while creating connection but here it accepts on the 2nd step?

-Sharj

5 Posts
Login to add your message