天翎MyApps技术社区 - 低代码平台 | 流程管理系统 | BPM软件

 找回密码
 注册成为天翎用户
查看: 2495|回复: 0

[webservice] 如何通过在java中调用webservice接口得到数据

[复制链接]
myApps 发表于 2016-7-8 20:13:10 | 显示全部楼层 |阅读模式
本帖最后由 karrman 于 2017-1-11 16:03 编辑

Q:如何通过在java中调用平台webservice接口得到数据?
A:请参考以下脚本:
package webService;

public class SyncTest {

        public static void main(String[] args) {
                //部门同步
                String url="http://localhost:8080/obpm/services/DepartmentService";
                String pk ="11e6-4314-767bf282-a2bd-77e1f101bc4d";
                String xmlStr = "<cn.myapps.webservice.model.SimpleDepartment>/n"
                                + " <domainName>万佳信息工程公司</domainName>/n"
                                + " <id></id>/n"
                                + " <level></level>/n"
                        + " <name>部门111111111</name>/n"
                        + " <superiorName>Xml格式部门</superiorName>/n"
                        + " </cn.myapps.webservice.model.SimpleDepartment>/n";
                XfireClient xfireClient=new XfireClient();
                xfireClient.createDepartment(url, xmlStr);
                //xfireClient.getDepartment(url, pk);
                //xfireClient.updateDepartment(url, xmlStr);
                //xfireClient.deleteDepartment(url, pk);               

        }

}

package webService;

import java.net.MalformedURLException;

import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

import test.IAnyName;

/**
* 这是xfire客户端
* 创建
* @author Administrator
*
*/
public class XfireClient {
       
        public XfireClient(){
        }
       
        public String createDepartment(String url,String xmlStr){
                try {
                        Service service = new ObjectServiceFactory().create(TLInterface.class) ;  
                XFireProxyFactory factory = new XFireProxyFactory() ;
                        TLInterface tlInterface = (TLInterface) factory.create(service,url) ;
            String result=tlInterface.createDepartmentFromXML(xmlStr);
        } catch (Exception e) {  
            e.printStackTrace();  
        }
                return null;  
        }
}


package webService;

public interface TLInterface {
       
        public int createDepartmentFromXML(String xmlStr);
        public int updateDepartmentFromXML(String xmlStr);
        public String findDepartmentFormat2XML(String pk);
        public int deleteDepartment(String pk);
        }

本版积分规则

QQ|手机版|天翎MyApps技术社区 ( 粤ICP备11093750号 )

GMT+8, 2026-8-12 13:19

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表