to clarify my needs, it looks like: a) I must have a SOAP client in python b) an RPC protocol for call from Java -> Python, where I control both
sides, and need something that's easy to use.
Thanks a lot to all of you! I believe with the code Simon provided (separate thread) I will be able to use ZSI for the client against a WSDL server, which will solve "a". On the "b" front, I'm almost there with XML-RPC, but need another piece of help: I have a java client calling python server. The call succeeds - I printed out input values in the server method and they match what I passed in java. however, when Java tries to build an object from the response, I get a java.lang.NoClassDefFoundError. I tried both an integer and a string as return values (the simplest objects I could think of). I'm guessing Java doesn't understand how to map the python types to java types (?) I am using apache xml-rpc (version 3), with default options. Do you have an idea on what I did wrong? python and java sources attached. from what I read seems that types for basic types like string/int are explicit in the XML serialization of XML-RPC (and SOAP), but implicit in JSON, so maybe JSON would work more easily between the languages? If I try JSON, I saw there are several implementations in both Java and Python - can anyone point me to a good combination for both languages you have used? thanks again Ronnie On 6/7/07, Simon Robins <[EMAIL PROTECTED]> wrote:
For the Python side: a) steer clear of SOAP If you decide to carry on anyway... b) There's a simple example in the 'dive into python' free web book using the SOAPpy lib c) If your needs are more complex you'll need the ZSI libraries. I can give you the code I used in a demo at the python group - they're toy examples though. On 7 Jun 2007, at 07:53, Ronnie Maor wrote: > Does anyone have experience with RPC from Java to Python? > Trying to get this to work over either XML-RPC or SOAP (prefer > SOAP) but am having slow start due to lack of experience with any > of relevant parts :-( > Specific packages to use, tips, and especially working example code > would be very very appreciated > > thanks > Ronnie >
import time from SimpleXMLRPCServer import SimpleXMLRPCServer class A(object): def get(self,*args): print 'GET CALLED, args=%s' % (args,) return "ronnie" if __name__ == '__main__': server = SimpleXMLRPCServer(('localhost',8080)) server.register_instance(A()) try: print 'Starting server (press Ctrl-C to stop)' server.serve_forever() except KeyboardInterrupt: pass
import java.net.URL; import org.apache.xmlrpc.client.XmlRpcClient; import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; public class HelloRPC { /** * @param args */ public static void main(String[] args) { try { System.out.println("Trying XML-RPC..."); XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); config.setServerURL(new URL("http://127.0.0.1:8080")); XmlRpcClient client = new XmlRpcClient(); client.setConfig(config); //Object[] params = new Object[]{}; Object[] params = new Object[]{new Integer(33), new Integer(9)}; Object resobj = client.execute("get", params); String result = (String) resobj; System.out.println("Results was " + result.toString()); } catch (Exception e){ System.out.println("Caught Exception: " + e.getMessage()); } } }