将ofbiz的Service导出为webservice及其调用的实例
发布时间:2020-12-17 00:56:31 所属栏目:安全 来源:网络整理
导读: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 ? ?? a
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();
调用其服务的代码:
? ? ? ? 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());
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |