Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing a SOAP 1.2 server with Rails 3

SOAP? Why would you use that?

I am using Ruby Enterprise Edition and Rails 3 to write my web application. The application uses Ustream's Watershed white label broadcasting services to provide live streaming for my users. Unfortunately I have hit a snag during development. Watershed allows an application to provide it's own authentication layer through the implementation of a SOAP service on the application side of things. This authentication layer must be implemented in SOAP 1.2 to work with Watershed. To my great dismay, it seems that the Ruby community has moved on past ye'old SOAP towards a brighter future filled with REST and Unicorns.

This makes me happy 99.9% of the time. However right now I need to make a SOAP 1.2 endpoint in my shiny new Rails 3 application.

If anyone has any suggestions or libraries that I can use, I would be very thankful.

Things I have done already

  • Tried the built in SOAP support in Ruby. Unfortunatly it seems that it does not support SOAP 1.2.
  • Looked at WSO2 but didn't want to build an extensive set of Ruby extensions on my server just to support SOAP.
  • Thought about hard-coding xml responses before deciding that I am a lazy programmer.
like image 835
Carl Sverre Avatar asked Apr 15 '10 19:04

Carl Sverre


2 Answers

It's been a while since this Q was posted, but hey, SOAP isn't speeding off either. I guess you've implemented something, care to share?

Anyway, as a kind of answer, I've been blessed with a customer forcing me to consume his SOAP services (their awesome SOA platform doesn't support other formats...) both for pulling and pushing data. I only consume, as I provide nice and clean RESTful Web Services myself for others. I've been using savon (french for soap?) with great success

http://savonrb.com

If you're truly lazy, you'll hard code the SOAP envelope structure and input your dynamic data. Here's a simple example.

def soap_envelope(pCode)
  "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:prod='http://xmlns.aBigCompany.com/path/to/NeededService'>
     <soapenv:Header/>
     <soapenv:Body>
        <something:NeededServiceRequest>
           <something:productCode>#{pCode}</something:productCode>
        </something:NeededServiceRequest>
     </soapenv:Body>
  </soapenv:Envelope>"
end

And this is one way to use it

products_wsdl = Savon::Client.new "http://ipAtBigCo:xxxx/path/to/services/NeededService?wsdl"
begin
  response = products_wsdl.process! do |soap| 
    soap.xml = soap_envelope("someProductCode")
  end
rescue => e
  MyLogger.error "Error: SOAP call for code #{pCode} failed. ++"
  raise e
end
response.to_hash # This is the nice part 

About SOAP 1.2, savon supports it. About actually being a SOAP service provider, I haven't done it in rails (fight it!) and can only wish you good luck. Having to develop the stupid WSDLs yourself is the real pain with SOAP services. Hope this helps anyone.

like image 137
oma Avatar answered Sep 16 '22 18:09

oma


If you cannot avoid SOAP in Rails 3, then try wash_out gem. You can find it at: https://github.com/roundlake/wash_out

We used in our system. It is not fool-proof and still undergoing some changes, at least you would get started

Although Rails 3 onwards, they have kind-of stopped supporting SOAP - wash_out gem helps you to get started with creating SOAP webservice faster. Anyone interested should have a look at the wash_out wiki on github. In our case, client wanted a SOAP webservice to be exposed; we tried to go the REST way. In the end, we had to say yes to SOAP. I tried aws, soap4r - but wash_out turned out to be best fit.

like image 31
arrk-shoba Avatar answered Sep 16 '22 18:09

arrk-shoba