<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - Creating an API using XML-RPC library]]></title>
		<link>http://railsforum.com/viewtopic.php?id=32379</link>
		<description><![CDATA[The most recent posts in Creating an API using XML-RPC library.]]></description>
		<lastBuildDate>Thu, 02 Jul 2009 11:41:55 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Creating an API using XML-RPC library]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=102611#p102611</link>
			<description><![CDATA[<p>Hi All,</p><p>I want to create a API which will call the server and get the result from the server.<br />Presently just i have an basic idea on XML-RPC to timplement API&#039;s.<br />Just i tried to implement a simple API called &quot;getSum&quot; which is defined in my controller of the server.</p><p>To implement this i have written a client.rb code looks like:<br />----------------------------------------------------------------------<br />require &quot;xmlrpc/client&quot;</p><p># Make an object to represent the XML-RPC server.<br />server = XMLRPC::Client.new2( &quot;http://localhost/search/getSum&quot;)<br />puts &quot;sri&quot;<br /># Call the remote server and get our result<br />result = server.call(&quot;getSum&quot;,1,2)<br />if result<br />&nbsp; &nbsp; puts &#039;Hey, it worked!&#039;<br />&nbsp; else<br />&nbsp; &nbsp; puts &#039;Back to the drawing board...&#039;<br />&nbsp; end </p><p>#puts result<br />sum = result[&quot;sum&quot;]<br />puts &quot;Sum: #{sum}&quot;<br />--------------------------------------------------------------------------<br />from the above code &quot;http://localhost/search/getSum&quot;<br />&#039;search&#039; is the controller name and &#039;getSum&#039; is the method defined in controller.</p><p>My server code looks like this:<br />-----------------------------------------<br />class SearchController &lt; ApplicationController<br />def getSum(int num1,int num2)<br />sum = params[:num1] + params[:num2]<br />puts sum<br />return sum<br />end<br />----------------------------------------------</p><p>I have executed the client code like below on commond prompt:<br />&gt;ruby client.rb<br />c:/ruby/lib/ruby/1.8/xmlrpc/client.rb:546:in `do_rpc&#039;: HTTP-Error: 500 Internal<br />Server Error (RuntimeError)<br />&nbsp; &nbsp; &nbsp; &nbsp; from c:/ruby/lib/ruby/1.8/xmlrpc/client.rb:420:in `call2&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; from c:/ruby/lib/ruby/1.8/xmlrpc/client.rb:410:in `call&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; from client.rb:7</p><p>I am getting the error like HTTP-Error.</p><p>Then i looked in the log file of my server code, below error is coming:<br />------------------------------------------------------------------------<br />Processing SearchController#getSum (for 127.0.0.1 at 2009-07-02 17:08:00) [POST]<br />&nbsp; Parameters: {&quot;methodCall&quot;=&gt;{&quot;methodName&quot;=&gt;&quot;getSum&quot;, &quot;params&quot;=&gt;{&quot;param&quot;=&gt;[{&quot;value&quot;=&gt;{&quot;i4&quot;=&gt;&quot;1&quot;}}, {&quot;value&quot;=&gt;{&quot;i4&quot;=&gt;&quot;2&quot;}}]}}}<br />&nbsp; [4;36;1mSQL (0.0ms)[0m&nbsp; &nbsp;[0;1mSET NAMES &#039;utf8&#039;[0m<br />&nbsp; [4;35;1mSQL (0.0ms)[0m&nbsp; &nbsp;[0mSET SQL_AUTO_IS_NULL=0[0m<br />ArgumentError (wrong number of arguments (0 for 2)):<br />---------------------------------------------------------</p><p>Can any one suggest if i am doing any mistake?<br />Please suggest me to resolve this problem.</p><p>thanks All <br />Srikanth</p>]]></description>
			<author><![CDATA[dummy@example.com (srikanth)]]></author>
			<pubDate>Thu, 02 Jul 2009 11:41:55 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=102611#p102611</guid>
		</item>
	</channel>
</rss>
