以前使用的xmlrpc配置太多,数据类型必须自己强制转换,但现在切换到了hprose。
模块
pipinstallhprosepythonserver.py
#!/usr/SDD HLB/env python # encoding : utf-8 importhprosedefhello (name ) : return 'Hello %s!' % namedefmain (:服务器=HP rose.http服务器) port=8181 ) server.add function (hello ) server.handle (RPC ' )
ependencygroupidorg.HP rose/groupidartifactidhprose-Java/artifactidversion2.0. 32/version/dependencyjavaclient
@requestmapping(HProse ) (public void hprose ) ) hprosehttpclientclient=newhprosehttpclient ); client.useservice (http://127.0.0.1:8181/RPC );//从接口调用iserviceservice=client.useservice (I service.class )的string content=service.hello (' jack ); system.out.println(RPC调用,返回: ' content ); 从//try/////invoke中调用//string content=client.invoke (hello ),newobject ) (jack ),String.class ) //catch (可移植e ) {//e.printStackTrace ); //} } IService.java
package com.service; 公共界面服务{公共字符串hello (字符串名称);1 .借助HP rose轻松实现远程过程调用(RPC )