# XMLRPC calling question

**URL:** <https://www.ruby-forum.com/t/xmlrpc-calling-question/161172>\
**Category:** Rails\
**Created:** [February 24, 2009, 3:58am UTC](https://www.ruby-forum.com/t/xmlrpc-calling-question/161172 "2009-02-24T03:58:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Don\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Don\_F](https://www.ruby-forum.com/u/Don_F)\
**Post date:** [February 24, 2009, 3:58am UTC](https://www.ruby-forum.com/t/xmlrpc-calling-question/161172/1 "2009-02-24T03:58:05Z")

</div>

I have a mashup I need to d with a site that uses xmlrpc. I am trying  
to understand the the call method. I have the following items that  
need to be passed to the remote site.

methodName  
and the following structure  
ID - string  
area - string  
views = array of strings

I know what the xml should look like  
  
lists  
  
  
  
  
  
id  
  
12345  
  
  
  
list  
  
district  
  
  
  
View  
  
  
  
  
Ocean  
  
  
Mountain  
  
  
Golf Course  
  
  
Garden View

I have results from various inputs from the view for the value. I am  
trying to figure out how to create the xml structure and how to use it  
in the XMLRPC call.

Any help?

Don F.

---

<div class="post-metadata">

**Author:** ![Don\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Don\_F](https://www.ruby-forum.com/u/Don_F)\
**Post date:** [February 24, 2009, 4:04am UTC](https://www.ruby-forum.com/t/xmlrpc-calling-question/161172/2 "2009-02-24T04:04:31Z")

</div>

erb. Set up a boilerplate file and fill in what you need. It’s MUCH  
faster than trying to generate it with REXML.

On Mon, Feb 23, 2009 at 6:57 PM, Don F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I know what the xml should look like  
> […lots of xml…]

---

<div class="post-metadata">

**Author:** ![Don\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Don\_F](https://www.ruby-forum.com/u/Don_F)\
**Post date:** [February 24, 2009, 5:16am UTC](https://www.ruby-forum.com/t/xmlrpc-calling-question/161172/3 "2009-02-24T05:16:29Z")

</div>

OK I can do that, but how is that result string of xml passed to the  
server I have a variable remote\_server that was created with the  
XMLRPC::Client.new2 call. how do I then call the method “search” on  
that serve?

Don F.

---

<div class="post-metadata">

**Author:** ![Don\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Don\_F](https://www.ruby-forum.com/u/Don_F)\
**Post date:** [February 24, 2009, 7:52am UTC](https://www.ruby-forum.com/t/xmlrpc-calling-question/161172/4 "2009-02-24T07:52:42Z")

</div>

Why not

require ‘xmlrpc/client’  
@server = XMLRPC::Client.new((secure) ? MY\_SECURE\_URN : MY\_URN,  
MY\_ENDPOINT, nil, nil, nil, nil, nil, secure)  
@server.call(‘my.method.name’, {:id =\> 1, :area =\> ‘someplace’}

etc.

I’ve had nothing but good results from xmlrpc. Any reason not to use it?

---

<div class="post-metadata">

**Author:** ![Don\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Don\_F](https://www.ruby-forum.com/u/Don_F)\
**Post date:** [February 24, 2009, 7:37pm UTC](https://www.ruby-forum.com/t/xmlrpc-calling-question/161172/5 "2009-02-24T19:37:31Z")

</div>

Thank you. I assume the args parameter is a hash of the variou values  
to be put into the XML. Correct?  
Does the call method actually generates the XML as I described, or do  
I have to generate it?

Don F.

---

<div class="post-metadata">

**Author:** ![Don\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Don\_F](https://www.ruby-forum.com/u/Don_F)\
**Post date:** [February 24, 2009, 5:27pm UTC](https://www.ruby-forum.com/t/xmlrpc-calling-question/161172/6 "2009-02-24T17:27:09Z")

</div>

I access 3rd party software through xmlrpc calls. I built mine as a  
plugin… but i’ll extract some of it for you in this example below:

require “xmlrpc/client”

def api\_perform(class\_type, method, _args)  
begin  
server = XMLRPC::Client.new3({‘host’ =\> @api\_url, ‘path’ =\> “/api/  
xmlrpc”, ‘port’ =\> 443, ‘use\_ssl’ =\> true})  
result = server.call("#{class\_type}.#{method}", @api\_key, args)  
rescue XMLRPC::FaultException =\> e  
puts "_\* Error: #{e.faultCode} - #{e.faultString} \*\*\*"  
end

return result  
end

The result that’s returned is a Hash.

Hope this helps.
