栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

金蝶创建webservice接口和调用

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

金蝶创建webservice接口和调用

注意:因为文件缺失webservice这部分是以3个功能来描述的

webservice金蝶有标准接口可以在金蝶社区找到文档,自己写一个webservice接口需要在金蝶bos设计开发工具matedata目录下新建一个功能。

注意:功能命名结尾要以Facade结尾

功能建完后再到 方法里面完成方法的命名、返回值、参数命名、参数类型的设置。

完成后再右键方法名先发布功能再发布webservice(发布webservice时要勾选参数) 

接着在java模块刷新解决方案,会自动生成对应的controllerbean等文件,将发布出来的webservice文件导入 到对应的目录下

找到新建功能对应的controllerbend(功能名加controllerbean)

在controllerbean内重写webservice方法 

@Override
    protected String _getUsernamEas(Context ctx, String IdCard){
    	System.out.println("IdCard:"+IdCard);
    JSonObject js = new JSonObject();
	JSonArray jsonArray = new JSonArray();
	
	if(IdCard == null){
		js.put("statue", false);
		js.put("msg", "身份证号为空!");
		return js.toString();
	} else {
		PersonCollection personInfo = null;
		try {
			personInfo = PersonFactory.getLocalInstance(ctx).getPersonCollection(" where idCardNo = '" + IdCard + "'");
		} catch (BOSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			js.put("statue", false);
			js.put("msg", "身份证号不存在");
			return js.toString();
		}
		
		String number=null;
		UserCollection userInfo=null;
		if ( personInfo.size()>0) {
			String id=personInfo.get(0).getId().toString();
			 try {
				 userInfo = UserFactory.getLocalInstance(ctx).getUserCollection(" where person = '" + id + "'");
			} catch (BOSException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			//查询number,即用户的username
			if(userInfo.size()>0){
				number= userInfo.get(0).getNumber();
				js.put("number", number);
			}else{
				js.put("statue", false);
				js.put("msg", "eas系统中该用户不存在");
				
				return js.toString();
			}
		 }else {
			 js.put("statue", false);
			 js.put("msg", "身份证号:"+"'"+IdCard+"'不存在");
				return js.toString();
		}
	}
    	return js.toString();
    }

接着就是编写demo测试接口

启动bos开发工具进入http://localhost:56898/ormrpc/services链接查找创建的webservice

调用EAS webservice示例

访问http://EAS的IP: 端口/ormrpc/services,下载调用wsdl

  

打开eclipse新建一个项目点击右键选择New下的Other(快捷键Ctrl+N)

点击Other,选择 Web Service包下的 Web Service Client点击Next

点击 Next 进入Web Services

  

新建一个java类直接调用

测试类代码

package test;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Stub;

import client.WSContext;

import deptfacade.client.WSInvokeException;

import localhost.ormrpc.services.EASLogin.EASLoginProxy;

import localhost.ormrpc.services.EASLogin.EASLoginProxyServiceLocator;

import localhost.ormrpc.services.WSDeptFacade.WSDeptFacadeSrvProxy;

import localhost.ormrpc.services.WSDeptFacade.WSDeptFacadeSrvProxyServiceLocator;

public class TestInterfaceFacade {

    public static void main(String[] args) {

         EASLoginProxyServiceLocator locator = new EASLoginProxyServiceLocator();

         EASLoginProxy proxy = null;

         try {

         proxy = locator.getEASLogin();

//          用户名,密码,固定值eas,861数据中心编码,固定值L2,2是orcale数据库

            WSContext wscontext=proxy.login("eas", "kdesa", "eas", "861", "L2", 2);

            System.out.println(wscontext.getSessionId());

            if(wscontext.getSessionId()!=null&&wscontext.getSessionId()!="") {

                Dept(wscontext);      

            } else {

                System.out.println("登录EAS失败,请确认登录信息是否正确");

            }

           

        } catch (Exception e) {

            e.printStackTrace();

        }finally {

            if(proxy != null) {

                try {

                   proxy.logout("user", "kduser", "eas", "861");

                } catch (RemoteException e) {

                   e.printStackTrace();

                }

            }

        }

        }

   

//  部门接口

    private static void Dept(WSContext wscontext) throws ServiceException, WSInvokeException, RemoteException {

        WSDeptFacadeSrvProxyServiceLocator dLocator=new WSDeptFacadeSrvProxyServiceLocator();

        WSDeptFacadeSrvProxy dProxy=dLocator.getWSDeptFacade();

        ((Stub)dProxy).setHeader("http://login.webservice.bos.kingdee.com", "SessionId",wscontext.getSessionId());

//      调用部门编码number

        String dresults=dProxy.query("10910");

        System.out.println(dresults);

    }

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/713206.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号