What is XML-RPC?
XML-RPC is the originator of XML Web Services. It is a simple specification for Remote Procedure Call (RPC), which uses HTTP as the transmission protocol and XML vocabulary as the message payload. Since the XML-RPC is very simple (the entire specification is printed out less than ten pages), it has become very popular and now most languages have standard or already available XML-RPC implementations. These languages include python, which began bundling xmlrpclib (XML-RPC implementation developed by Fredrik lundh) in version 2.2. |
First, we plan to transform the CMS (context Manager System) system into python. The first thing is to make public version changes for remote calls.
Import simplexmlrpcserver # Define your own CMS class Class mycms: Def getversion (Self): # Release Method Return "powerd by Python 0.1a" CMS = mycms () Server = simplexmlrpcserver. simplexmlrpcserver ("localhost", 8888 )) Server. register_instance (CMS) Print "listening on port 8888" Server. serve_forever () # Run the command on the server and listen to port 8888. |
After execution:
Images related to this topic
The client calls the code to obtain the latest version information.
Import xmlrpclib Server = xmlrpclib. serverproxy ("http: // localhost: 8888" Version = server. getversion () Print "version:" + version |
After execution:
Images related to this topic
Summary:
Significantly less than the same Java implementation code, enabling more focus on the system itself
Java XMLRPC implementation: http://ws.apache.org/xmlrpc/
The Java call code is as follows:
Xmlrpcclient XMLRPC = NULL; Try { XMLRPC = new xmlrpcclient ("http: // localhost: 8888 /";); } Catch (malformedurlexception E) { E. printstacktrace (); } Vector Params = new vector (); Try { String result = (string) xmlrpc.exe cute ("getversion", Params ); System. Out. println (result ); } Catch (xmlrpcexception E1) { E1.printstacktrace (); } Catch (ioexception E1) { E1.printstacktrace (); } |
Execution result
Images related to this topic
For more information, please go here:
Http://www.python.org/doc/current/lib/module-xmlrpclib.html
Http://www.python.org/doc/current/lib/module-SimpleXMLRPCServer.html