|
Posted by Dhepthi L Narasimhan on March 23rd, 2012
Rhomobile is cross-platform mobile framework to develop native application. The documentation for developing native app is nice. I recently tried consuming webservice using savon gem in rhoconnect. The most tricky part is to get input from rhodes application and use that as a parameters in rhoconnect webservice call. The gist of things needed for making SOAP call are
We will use http://www.webservicex.net/length.asmx?WSDL webservice to consume and manipulate response in rhoconnect. Let’s see how to make these things work. 1. Sample Rhodes Application with search action
rhodes app rhodes-unit-webservice rhodes model Unit value,from,to Enable sync in Model to connect to rhoconnect class Product enable :sync end Pass inputs given by user to rhoconnect search action
def search
Unit.search(
:from => 'search',
:search_params => {
:Value => @params['unit']['value'],
:From => @params['unit']['from'],
:To => @params['unit']['to']
},
:callback => url_for(:action => :search_callback),
:callback_param => ""
)
render :action => :wait
end
We will implement search callback after SOAP request done in rhoconnect. Now let’s see what to do in rhoconenct 2. Rhoconnect Application with SOAP webservice call in search action
rhoconnect app rhoconnect-unit-webservice rhoconnect source Unit Add savon gem in Gemfile gem 'savon' Call ChangeLengthUnit method in webservice using savon
require 'savon'
@webservice_url = "http://www.webservicex.net/length.asmx?WSDL"
client = Savon::Client.new(@webservice_url )
data= client.request :change_length_unit do
soap.body = {
"LengthValue" => params["Value"],
"fromLengthUnit" => params["From"],
"toLengthUnit" => params["To"]
}
end
puts data.to_hash
Here data.to_hash has the response of webservice called. We will get inputs for this SOAP request from rhodes search action. We can access those params in rhoconnect search action as
def search(params)
# params - values from rhodes
end
We will assign the response of SOAP call to @result which will in turn stores in redis database as shown
puts data.to_hash
@result = data.to_hash
@result
3. Display SOAP response from rhoconnect
def search_callback
status = @params["status"]
if status == "complete"
data = Unit.find_all
data.each do |val|
Alert.show_popup("The Converted value is #{val.change_length_unit_result}")
end
WebView.navigate(url_for :action => :index)
end
end
All values stored in rhoconnect can be retrieved through find query. This is how we consume SOAP webservice from rhodes through rhoconnect. Some of the screenshots taken from Iphone Mobile I hope this blog will be helpful for making SOAP request in rhomobile. Source code of rhodes and rhoconnect application is available at https://github.com/Dhepthi/rhodes-unit-webservice, https://github.com/Dhepthi/rhoconnect-unit-webservice.Please feel free to improve and send me a pull request. Any suggestion or comments are welcome. Tags: rhoconnect, rhodes, rhomobile, RubyUnique Views: 1315 Total views: 1946 Follow responses at RSS 2.0. Leave a response | Trackback. 2 Responses to “Consume SOAP webservice in rhoconnect”Leave a Reply |
Error hitting like this…can you mail how to run this code
APP| [Debugger] Unable to open connection to debugger: #
APP| Params: {“sync_type”=>”incremental”, “status”=>”error”, “error_code”=>”7″, “error_message”=>”", “rho_callback”=>”1″, “search_params”=>{“Value”=>”6″, “From”=>”Feet”, “To”=>”Inches”}}
Error hitting on me…can you mail how to run this code..