XML-RPC example of Apache

Source: Internet
Author: User

An example on the Internet is implemented in Java, that is, Apache XML-RPC:

 

Computing class (a server service, of course, can be written by yourself ):

Package COM. XMLRPC. server; <br/> public class calculator {<br/> Public int add (INT I1, int I2) {<br/> return I1 + I2; <br/>}< br/> Public int subtract (INT I1, int I2) {<br/> return I1-I2; <br/>}< br/>}

 

Server:

Package COM. XMLRPC. server; </P> <p> Import Org. apache. XMLRPC. server. propertyhandlermapping; <br/> Import Org. apache. XMLRPC. server. xmlrpcserver; <br/> Import Org. apache. XMLRPC. server. xmlrpcserverconfigimpl; <br/> Import Org. apache. XMLRPC. webserver. webserver; </P> <p> public class server {<br/> Private Static final int Port = 9999; </P> <p> Public static void main (string [] ARGs) throws exception {<br/> webserver = new webserver (port ); <br/> xmlrpcserver = webserver. getxmlrpcserver (); <br/> propertyhandlermapping PHM = new propertyhandlermapping (); <br/> PHM. addhandler ("Calculator", calculator. class); <br/> xmlrpcserver. sethandlermapping (PHM); <br/> xmlrpcserverconfigimpl serverconfig = (xmlrpcserverconfigimpl) xmlrpcserver. getconfig (); <br/> serverconfig. setenabledforextensions (true); <br/> serverconfig. setcontentlengthoptional (false); <br/> webserver. start (); <br/>}< br/>

 

Client:

Package COM. XMLRPC. client; </P> <p> Import java.net. URL; <br/> Import Org. apache. XMLRPC. client. xmlrpcclient; <br/> Import Org. apache. XMLRPC. client. xmlrpcclientconfigimpl; <br/> public class client {<br/> Public static void main (string [] ARGs) throws exception {<br/> // create configuration <br/> xmlrpcclientconfigimpl Config = new xmlrpcclientconfigimpl (); <br/> config. setserverurl (new URL ("http: // localhost: 9999/XMLRPC"); <br/> config. setenabledforextensions (true); <br/> config. setconnectiontimeout (60*1000); <br/> config. setreplytimeout (60*1000); <br/> xmlrpcclient client = new xmlrpcclient (); <br/> client. setconfig (config); <br/> object [] Params = new object [] {New INTEGER (2), new INTEGER (3 )}; <br/> integer result = (integer) client.exe cute ("Calculator. add ", Params); <br/> system. out. println ("Result:" + result); <br/>}< br/>}

 

Finally, start the server and then run the client. For more information about the code, see http://ws.apache.org/xmlrpc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.