# N00b question on passing parameters to a webservice

**URL:** <https://www.ruby-forum.com/t/n00b-question-on-passing-parameters-to-a-webservice/138369>\
**Category:** Rails\
**Created:** [May 22, 2008, 11:27am UTC](https://www.ruby-forum.com/t/n00b-question-on-passing-parameters-to-a-webservice/138369 "2008-05-22T11:27:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rey9999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@Rey9999](https://www.ruby-forum.com/u/Rey9999)\
**Post date:** [May 22, 2008, 11:27am UTC](https://www.ruby-forum.com/t/n00b-question-on-passing-parameters-to-a-webservice/138369/1 "2008-05-22T11:27:43Z")

</div>

Let us say I have a webservice method:  
api\_method :login, :expects =\>  
[:name=\>:string, :password=\>:string], :returns =\> [:int]

defined as:

def login(name, password)

#do something here and returns an int  
end

how do exacly pass it the two parameters from the client?  
I tried:

- @ws\_client.login(‘user’, ‘mypwd’)

- @ws\_client.login({:name =\>‘user’, :password=\>‘mypwd’})

- @ws\_client.login([‘a’,‘b’])

No matte what, I always get:  
“wrong number of arguments (1 for 2)”

When edit the method to accept just one parameter, and call it with:  
@ws\_client.login(‘user’)  
everything runs fine.

I’m sure I’m missing something _very_ obvious. Please help…

Thanks in advance

Rey9999

---

<div class="post-metadata">

**Author:** ![Rey9999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@Rey9999](https://www.ruby-forum.com/u/Rey9999)\
**Post date:** [May 22, 2008, 12:21pm UTC](https://www.ruby-forum.com/t/n00b-question-on-passing-parameters-to-a-webservice/138369/2 "2008-05-22T12:21:29Z")

</div>

Rey9999 wrote:

> “wrong number of arguments (1 for 2)”
> 
> When edit the method to accept just one parameter, and call it with:  
> @ws\_client.login(‘user’)  
> everything runs fine.  
>   
> From one n00b to another 😉

Have you tried this?

@ws\_client.login(:name =\>‘user’, :password=\>‘mypwd’)

I would have thought this would have worked (I don’t know why it  
doesn’t):

@ws\_client.login(‘user’, ‘mypwd’)

…but these won’t work :

@ws\_client.login({:name =\>‘user’, :password=\>‘mypwd’})

@ws\_client.login([‘a’,‘b’])

…because Ruby sees the Hash and Array as a single argument

---

<div class="post-metadata">

**Author:** ![Rey9999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@Rey9999](https://www.ruby-forum.com/u/Rey9999)\
**Post date:** [May 22, 2008, 2:17pm UTC](https://www.ruby-forum.com/t/n00b-question-on-passing-parameters-to-a-webservice/138369/3 "2008-05-22T14:17:33Z")

</div>

Thank you!  
I’ll try as soon as possible.

---

<div class="post-metadata">

**Author:** ![Rey9999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@Rey9999](https://www.ruby-forum.com/u/Rey9999)\
**Post date:** [May 22, 2008, 3:02pm UTC](https://www.ruby-forum.com/t/n00b-question-on-passing-parameters-to-a-webservice/138369/4 "2008-05-22T15:02:52Z")

</div>

On 22 May 2008, at 13:16, Rey9999 wrote:

> Thank you!  
> I’ll try as soon as possible.
> 
> On 22 Mag, 12:20, Rory McKinley [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Rey9999 wrote:
> > 
> > > Let us say I have a webservice method:  
> > > api\_method :login, :expects =\>  
> > > [:name=\>:string, :password=\>:string], :returns =\> [:int]

that should be :expects =\> [{:name =\> :string}, {:password =\> :string}]

then you should be able to just do @ws\_client.login(‘user’, ‘password’)

Fred

---

<div class="post-metadata">

**Author:** ![Rey9999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@Rey9999](https://www.ruby-forum.com/u/Rey9999)\
**Post date:** [May 23, 2008, 10:36am UTC](https://www.ruby-forum.com/t/n00b-question-on-passing-parameters-to-a-webservice/138369/5 "2008-05-23T10:36:09Z")

</div>

Ok, the lucky combination was:

:expects =\> [{:name =\> :string}, {:password =\> :string}] #in the  
service definition

@ws\_client.login({:name =\>‘user’, :password=\>‘mypwd’}) # in the method  
call.

Now it works beautifully.  
Thanks a lot, everyone!

Rey9999
