# ActiveWebService returning custom types

**URL:** <https://www.ruby-forum.com/t/activewebservice-returning-custom-types/161762>\
**Category:** Rails\
**Created:** [March 2, 2009, 7:54am UTC](https://www.ruby-forum.com/t/activewebservice-returning-custom-types/161762 "2009-03-02T07:54:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wanyixue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/958977/32.png) [@wanyixue](https://www.ruby-forum.com/u/wanyixue)\
**Post date:** [March 2, 2009, 7:54am UTC](https://www.ruby-forum.com/t/activewebservice-returning-custom-types/161762/1 "2009-03-02T07:54:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wanyixue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/958977/32.png) [@wanyixue](https://www.ruby-forum.com/u/wanyixue)\
**Post date:** [March 2, 2009, 7:56am UTC](https://www.ruby-forum.com/t/activewebservice-returning-custom-types/161762/2 "2009-03-02T07:56:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wanyixue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/958977/32.png) [@wanyixue](https://www.ruby-forum.com/u/wanyixue)\
**Post date:** [March 2, 2009, 9:43am UTC](https://www.ruby-forum.com/t/activewebservice-returning-custom-types/161762/3 "2009-03-02T09:43:06Z")

</div>

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 ?
