We wanted to consume simple SOAP based web services from the iPhone, Android applications using RhoMobile framework. We dont want to use Savon as it got too much dependency to become rhodes-ruby extension.
Just thought lets write the raw soap client without using SOAP gems. Rhodes already support net-http and rexml(rhoxml) for such tasks.
The sample source code can be found at https://github.com/spritle/rhodes_soap_test/blob/master/app/Soap/soap_controller.rb which basically consume the SOAP services from http://www.w3schools.com/webservices/tempconvert.asmx
The basic steps involve on the controller side involves:
- Initialize the http object with soap service url
[source language=”ruby”]
http = Net::HTTP.new(‘www.w3schools.com’, 80)
path = ‘/webservices/tempconvert.asmx’ [/source] - Create the SOAP Request envelope
[source language=”ruby”]
data = <<-EOF
#{celsius}
EOF
[/source] - Set Headers if required
[source language=”ruby”]
headers = {
‘Content-Type’ => ‘text/xml’,
‘Host’ => ‘spritle.com’
}
[/source] - Make the http request and then process the result data
[source language=”ruby”]
resp, data = http.post(path, data, headers)
puts data
[/source] - Sample SOAP Response
[source language=”ruby”]
89.6
[/source]
If you want you can also the process the SOAP Response string using XML parsers like rhoxml.
Example:
[source language=”ruby”]
xmldoc = REXML::Document.new(data)
xmldoc.elements.each(“soap:Envelope/soap:Body/CelsiusToFahrenheitResponse/CelsiusToFahrenheitResult”) { |e| puts e.text
}
[/source]
If you want to see how we can use savon as rhodes-ruby-extensions, please leave us a comment so that we can share our code on Github.
Hi.
I’m trying to use savon with RhoMobile, can you share your code?
Thank you in advance,
jpsfs
I am trying to use savon with rhomobile, and getting into a lot of trouble with its dependencies….
If you got a sample running, can you post it?
Thanks!
Sorry we dont have a sample for it. We opt for custom http post than going through the gem dependencies pain of savon.
I am trying to consume a soap webservice in a rhomobile app, so this blog looked perfect.
However I have added to the extensions in the build file but I must be missing something (very new to rhodes/ruby)
When I try to create the http object on 1. I get an error.
I’m getting ‘source not found’ within a tab labelled ‘extensions/net-http/net/http’
Any help appreciated – thanks.
Hi,
I am trying to consume SOAP service likewise and it is working good in rho simulator but when I bulid it on wondows mobile CE 6.5, application closes as soon as I click on my button to call that action, I have used my SOAP service almost the same way as it shown above
please help