Using Savon Rb to communicate with SOAP client (http basic authentication and no WSDL file)

Most of the time, when we connect to webservices via SOAP (via SOAP! via SOAP! ;)), we have a WSDL file either local or downloaded from a server. But sometimes we need to connect to SOAP server which does not have this file and it is secured with http basic authentication.

To communicate with SOAP I use Savon Rb. It is easy and relatively fast. However in documentation there is nothing about communication with http basic authentication protected resources.

Although setting things up is really easy. First authentication:

@soap_client = Savon::Client.new do
  # Set basic authorization
  http.auth.basic "user_name", "password"
end

and non-wsdl connection:

@soap_client = Savon::Client.new do
  wsdl.endpoint = "http://service.example.com"
  wsdl.namespace = "http://v1.example.com"
end

and that's all. Now we can execute remote method like this:

@soap_client.request :get_items

or with params:

@last_response = @soap_client.request :get_items do
  soap.body = {
    :param_1 => "value_1",
    :param_2 => "value_2",
  }
end

Categories: Ruby, Software

2 Comments

  1. Thanks dude. I was looking for an example of basic auth for a while.

  2. Thank you soo much !! Was looking for this too.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Copyright © 2024 Closer to Code

Theme by Anders NorenUp ↑