2

Im trying to connect to a SOAP URL with a Ruby script.

I am following this Railscasts episode. I installed the savon gem(savon (2.4.0)).

Then in my ruby file I have this code:

 require 'savon'

 client = Savon.client(wsdl:"https://api.comscore.com/KeyMeasures.asmx?WSDL")
 response = client.call(:authenticate , message: { username:"xxxxx", password:"xxxxx"})

 puts "#{response.inspect}"

I know there is no issue with the url because I used SOAPUI and placed the WSDL URL there and I got back a response.

When I run the ruby file above I get the following exception:

  /Users/XXXX/.rvm/gems/ruby-2.0.0-p247/gems/wasabi-3.2.3/lib/wasabi/resolver.rb:44:in `load_from_remote': Error: 401 (Wasabi::Resolver::HTTPError)
from /Users/XXXXX/.rvm/gems/ruby-2.0.0-p247/gems/wasabi-3.2.3/lib/wasabi/resolver.rb:32:in `resolve'

After googling about I saw this post, which seems to suggest that I should install and require gem "httpclient" which I did and then tried again. No changes, Still getting the same error.

Can someone give me a hand as to how to proceed .....

Thanks

Community
  • 1
  • 1
banditKing
  • 9,405
  • 28
  • 100
  • 157
  • Does the Savon's created envelope match SOAP UI's created one? Specifically the authentification part. – Magnuss Apr 10 '14 at 14:36
  • How do I check Savon's created envelope? – banditKing Apr 10 '14 at 14:37
  • Well, when you execute `client.call` e.g. in your console, don't you see an output like ` – Magnuss Apr 10 '14 at 14:55
  • I have the above code in a *.rb file. I invoke the script at the command line. The first thing I see after is the error. I do not get any response back. – banditKing Apr 10 '14 at 15:03
  • In your tags you mentioned `ruby-on-rails`, so run `rails console` and from there create the `client` and execute the `client.call`, because that error is related to response not the request. I don't know how else to get the request's output. :) – Magnuss Apr 10 '14 at 15:16
  • The error is thrown from Wasabi. Im digging through the source code now. On this link, the error is thrown at line 44: https://github.com/savonrb/wasabi/blob/master/lib/wasabi/resolver.rb#L40 The error code of the response is 401, which means there is something going on with the authentication headers being rejected. I know the authentication works with SOAPUI, Ive tested it and gotten a response back. Its just not working with Savon. This means that maybe my syntax is wrong with Savon or more likely there is something to do with Wasabi and httpclient. – banditKing Apr 10 '14 at 15:24
  • Here is the same issue being discussed:https://github.com/savonrb/savon/issues/504 – banditKing Apr 10 '14 at 15:28
  • I had same issue with https request. and adding 'httpclient' gem is really fixed it. – ajahongir Feb 20 '15 at 13:44
  • I was getting this error because I was sending my authenticated request (with a Bearer token) to a wrong endpoint, which does not use authentication, although is listening for the same kind of SOAP requests (same application). – jonypera Dec 14 '21 at 13:16

1 Answers1

5

I tried to access the WSDL you provided using curl from the commandline. I cannot access the WSDL b/c I'm not authorized. I guess that first you have to provide the credentials as part of your https request. That's why wasabifails. It cannot find the WSDL document.

According to the documentation that can be done by injecting the following code into your client creation:

client = Savon.client(wsdl: ...,
                      basic_auth: [ 'username', 'password' ],
                      log: true,
                      log_level: :debug,
                      pretty_print_xml: true)
client.call(...)
Steffen Roller
  • 3,464
  • 25
  • 43