Forum: Ruby on Rails ActiveWebService returning custom types

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Lin W. (Guest)
on 2009-03-02 08:54
class Sampleclass
 attr_reader :temp_arr,:temp_hash,:temp_str
  def initialize(temp_arr,temp_hash,temp_str)
    @temp_arr=temp_arr
    @temp_hash=temp_hash
    @temp_str=temp_str
  end

class TestApi < ActionWebService::API::Base
   api_method :get_me, :returns => [Sampleclass]
end

class TestController < ApplicationController
  wsdl_service_name 'Test'
  web_service_api TestApi
  web_service_scaffold :invocation if Rails.env == 'development'

  def get_me
    #[get_indices(),get_stocks(),get_summary(),DateTime.now.to_s]
    indices = get_indices()
    stocks = get_stocks()
    summary = get_summary()
    current_time = DateTime.now
    tempsnapshot = Snapshot.new(indices,stocks,summary,current_time)
    tempsnapshot
    [Sampleclass.new(['1','2',3'],
                     {'a' => '1',
                      'b' => '2' },
                     'something' ) ]
  end
end


i got this error
Don't know how to cast Sampleclass to Sampleclass

how do i define custom classes as return paramters
Lin W. (Guest)
on 2009-03-02 08:56
disregard this section
     #[get_indices(),get_stocks(),get_summary(),DateTime.now.to_s]
     indices = get_indices()
     stocks = get_stocks()
     summary = get_summary()
     current_time = DateTime.now
     tempsnapshot = Snapshot.new(indices,stocks,summary,current_time)
     tempsnapshot
Lin W. (Guest)
on 2009-03-02 10:43
nevermind the above posts
i wasnt paying attention


i created a model Sample

changed code to

class TestApi < ActionWebService::API::Base
   api_method :get_me, :returns => [Sample]
end

class MarketdataController < ApplicationController
   ...
  def poll
    Sample.find(:all,:limit =>1)
  end


here i get all sorts of mapping errors

#1
returns => [Sample]    #it should expect a Sample object

i return a Sample.find(:all,:limit=>1)[0]
and i get a "Cannot map Sample to SOAP/OM"

i return a Sample.find(:all,:limit=>1) #which would return an array
containing Sample objects , it errors out and says
"Don't know how to cast Array to Sample"
thats expected

then i tried this
#2
returns => [[Sample]] #it should expect an array of sample objects ?
i return a sample.find(:all,:limit=>1)
and i get a "Cannot map Array to SOAP/OM"


Any ideas on how to get it to cast properly ?
This topic is locked and can not be replied to.