Service定义:
<service name="test.add" engine="java" auth="
true" export="
true"
location="org.aries.erp.practice.TestServices"
invoke="add">
<attribute name="a" type="Integer" mode="IN" optional="false" ></attribute>
<attribute name="b" type="Integer" mode="IN" optional="false"></attribute>
<attribute name="result" type="Integer" mode="OUT" optional="false"></attribute>
</service>
Service代码:
public static Map<String, Object> add(DispatchContext dctx, Map<String, Object> context){
Map<String, Object> resultMap = ServiceUtil.returnSuccess();
Integer a = (Integer) context.get("a");
Integer b = (Integer) context.get("b");
resultMap.put("result", a + b);
return resultMap;
}
调用其服务的代码:
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("
http://127.0.0.1:8080/webtools/control/xmlrpc"));
config.setEnabledForExceptions(true);
config.setEnabledForExtensions(true);
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
Map paramMap = new HashMap();
paramMap.put("a", 3); //参数
paramMap.put("b", 5); //参数
paramMap.put("login.username", "admin"); //用户名
paramMap.put("login.password", "ofbiz"); //密码
Object[] params = new Object[]{paramMap};
Map result = (Map) client.execute("
test.add", params);
System.out.println(result.toString());