#290 SOAP with Savon
Communicating with a SOAP API can be a daunting task. Savon makes this easier by presenting the SOAP API through a Ruby interface.
- Download:
- source codeProject Files in Zip (77.4 KB)
- mp4Full Size H.264 Video (23.8 MB)
- m4vSmaller H.264 Video (13.3 MB)
- webmFull Size VP8 Video (13.4 MB)
- ogvFull Size Theora Video (34.1 MB)
Thanks Ryan..
Nice to see this as a screencast.
We once wrote a small app that consume complex types objects using Savon.
Please see https://github.com/spritle/awssoap4r
We wrote a small blog as well http://www.spritle.com/blogs/2011/09/28/consume-soap-webservices-using-ruby-with-savon/
Thought this might help your followers/readers
Regards
Balaji, Spritle Software
Good cast for me.
What about errors handling raised by Savon?
Only by request.succes? ?
Regards
Sssebaaa
there are 3 types of errors, one from the SOAP service it self, one from savon and one from the communications gem ( timeout error or no response) for the first one the web service should be able to notify of the error somehow (return a status tag) so you can handle that without the need of a begin rescue block the other cases are handled with with beging rescue.
Awesome as alway.
Ryan i will take this opportunity to motivate a topic that i think you have work with and i did have to solve when dealing with savon. The web service i comunicate with takes a couple of second to respond ( the rails app waits and does not answer to user request), so i took an approach i saw you using in episode 243, i used beanstalk and stalker, but then came the problem of updating the view instantly without the need to refresh the page when stalker/beanstalk finish.
Apparently i was the only one who didnt know how it was done but i still could not find a good example. Then in episode 281 i saw you were using faye with stalker.
I did figure out how to update the view with faye from stalker, but, could you touch this topic in a future episode? i think is a very common problem and there is not much documentation out there about how to update the view asynchronously after a background process finishes working.
Thanks for the suggestion. Pushing API requests into a background process is a good thing and would make a good episode. Good idea.
Oh, one other thing, it is also posible and very easy to read the values with nokogiri using a css selector.
I find it most useful when dealing with collections
Hey rbritom,
since Savon v0.9.7, the response object comes with a #doc method which returns a (memoized) Nokogiri object:
zipcode = response.doc.css("USzip").inner_text
SWEET!!!!!!!
Ill use it in my next project which starts tomorrow. Thanks for sharing.
Savon means soap in French in case you want to know.
Exactly and Ryan's pronunciation is ... ahem ... pas tr
Thanks Ryan!
I used it in our project. Cool library!!!
Btw, take a look on em-net-http (https://github.com/jfairbairn/em-net-http). Sometimes SOAP server might respond slowly. I used this library with Savon to improve performance and I reached it.
Can you give any example, how to use em-net-http with Savon?
Regards
While on SOAP and webservice, the rails app that I work on is expected to expose couple of methods as SOAP Webservice. I know Ruby has ditched SOAP in favor of REST, but I really dont have an option as the client app expect it. Is there any gems out there that support creation of a SOAP web service on Rails 3.x?
Thanks!
As far as i know, Soap4r and ActionWebService are the only SOAP server libraries.
Unfortunately both of those aren't actively maintained, I doubt that either works on Ruby 1.9 (if you search you may find a fork of one or the other that could do the job).
Doing it yourself completely isn't as hard as you may think though. Today I finished up an article on my blog on this topic, the example service I present in it is written using Sinatra (and not Rails).
I'm working on building an example of the same SOAP service inside of a Rails app: https://github.com/mkremer/echo_service_rails. I'll expect this example to be finished somewhere in the coming days
I just finished the Rails implementation of the EchoService, hopefully it will be of use to someone :)
And also there is SimpleWS lib: https://github.com/mikisvaz/simplews
Which is actually a wrap around Soap4r but much easier to get started.
We used this to communicate with Yodlee API. Worked wonderfully!
I'm seeing some pretty serious redraw bugs with SoapUI (Mac 10.7.2, latest java update). Are there any other similar tools?
There is SOAPClient. It's very simple - not a near SoapUI in terms of features.
But it might be a plus for simple queries and testing. Was a god bless for me for some time. But as you go deeper there is no alternative SoapUI which is really a pain to use on Mac.
Thanks Ryan!
It was very useful, but a review is needed, Savon has changed a lot in version 2, and it's very important working with delayed jobs...
Ryan, as always great video.
But, I am having trouble with credentials need to get in to a secure Soap api. Also, now there is a new version of Savon. I was wondering if you can do a revised tutorial which will include using an action that requires login, if possible.
in savon 2 that will be
client = Savon.client(wsdl: "http://www.webservicex.net/uszip.asmx?WSDL", basic_auth: ["user", "secret"])
If someone like me is wondering about how the example lines are in savon 2, they are like this.
client = Savon.client(wsdl: "http://www.webservicex.net/uszip.asmx?WSDL")
client.operations
client.call(:get_info_by_zip, message: { "USZip" => "90210" })
Excellent screencast, Ryan Bates! I built it in Rails 4 and updated two lines to work with Savon 2. Thanks!
Hi Ryan, thanks very much for putting up your soap_app built with Rails 4, it really helped with another Soap project I'm working on!
Hi Ryan, for more complex requests where you need to specify the child and sub-child tags, ie. when the request value(s) needed are located / nested down the xml tree - how would you write this code with Savon?