1. 服务注册

    服务注册统一在 serviceconfig.xml 里定义,通过 wade-serviceconfig.dtd 约定格式,配置示例如下:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE serviceconfig PUBLIC "-//AILK WADE//WADE 4.0//CN"
    	"http://www.wade.com/service/dtd/wade-serviceconfig.dtd" [
    	<!ENTITY common SYSTEM "classpath:common.xml">
    	<!ENTITY saleserv SYSTEM "classpath:saleserv.xml">
    	<!ENTITY acctmanm SYSTEM "classpath:acctmanm.xml">
    ]>
    <serviceconfig>
    	<config>
    		<package name="quickstart" dir="/quickstart"/>
    		<package name="saleserv" dir="/saleserv"/>
    		<package name="acctmanm" dir="/acctmanm"/>
    	</config>
    	<service subsys="quickstart">
    		<entity name="QCS_CustMgrByName" path="com.ailk.quickstart.service.cust.CustService@queryCusts" svc="quickstart@QCS_CustMgrByName.svc" />
    		<entity name="QCS_CustMgrById" path="com.ailk.quickstart.service.cust.CustService@queryCust" svc="quickstart@QCS_CustMgrById.svc" />
    		<entity name="TCS_CustMgrEdit" path="com.ailk.quickstart.service.cust.CustService@editCust" svc="quickstart@TCS_CustMgrEdit.svc" />
    		<entity name="QCS_QueryAreasByParent" path="com.ailk.quickstart.service.examples.ExamplesService@queryAreasByParent" svc="quickstart@QCS_QueryAreasByParent.svc" />
    		<entity name="QCS_QueryDepartsByParent" path="com.ailk.quickstart.service.examples.ExamplesService@queryDepartsByParent" svc="quickstart@QCS_QueryDepartsByParent.svc" />
    		<entity name="QCS_QueryDepartKindsByEparchy" path="com.ailk.quickstart.service.examples.ExamplesService@queryDepartKindsByEparchy" svc="quickstart@QCS_QueryDepartKindsByEparchy.svc" />
    	</service>
    	&common;
    	&saleserv;
    	&acctmanm;
    </serviceconfig>
    

    【注】实体 ENTITY 引入指定的 classpath 是以以 classes/service/ 为相对目录;
    config 下 package 的 name 值必须唯一,dir 是以 classes/service/ 为相对目录;
    service 的 subsys 用来指定该服务由哪个子系统提供,service 下 entity 的 name 值必须唯一,path 是完整的类路径 @ 方法名,svc 是关联的服务定义文件;
    path 里指定的方法必须是如下枨式:
    public IDataset|IData|String|Boolean xxxx(IData data) throws Exceptioin
    public IDataset|IData|String|Boolean xxxx(IData data, Pagination pagination) throws Exceptioin

  2. 服务定义

    服务定义文件以 svc 为后缀,用来约定服务的输入、输出及上下文信息,通过 wade-service.dtd 约定格式,配置示例如下:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE service PUBLIC "-//AILK WADE//WADE 4.0//CN"
    	"http://www.wade.com/service/dtd/wade-service.dtd" [
    	<!ENTITY public SYSTEM "classpath:./inc/public.svc">
    ]>
    <service>
    	<description>客户信息编辑</description>
    	&public;
    	<input>
    		<param>
    			<name>CUST_ID</name>
    			<desc>客户标识</desc>
    		</param>
    	</input>
    	<output>
    		<param>
    			<name>CUST_NAME</name>
    			<desc>客户名称</desc>
    		</param>
    	</output>
    </service>
    

    【注】实体 ENTITY 引入指定的 classpath 是以 classes/service/ 为相对目录;
    public.svc 里定义了默认的上下文信息,内容如下:

    <head>
    	<input>
    		<param>
    			<name>STAFF_ID</name>
    			<desc>操作员工标识</desc>
    		</param>
    		<param>
    			<name>STAFF_NAME</name>
    			<desc>操作员工名称</desc>
    		</param>
    		<param>
    			<name>X_PAGINCOUNT</name>
    			<desc>分页记录总数</desc>
    		</param>
    		<param>
    			<name>X_PAGINSIZE</name>
    			<desc>每页显示条数</desc>
    		</param>
    		<param>
    			<name>X_PAGINCURRENT</name>
    			<desc>当前页</desc>
    		</param>
    		<param>
    			<name>X_PAGINSELCOUNT</name>
    			<desc>是否需要强制COUNT</desc>
    		</param>
    	</input>
    	<output>
    		<param>
    			<name>X_RESULTCODE</name>
    			<desc>返回结果编码(非0表示成功)</desc>
    			<type>int</type>
    		</param>
    		<param>
    			<name>X_RESULTINFO</name>
    			<desc>返回结果信息</desc>
    		</param>
    	</output>
    </head>
    
  3. 服务路由

    服务路由仍沿用原来的 td_m_naming,td_m_context 表,开发时完全可以不使用该功能,直接在本地调用服务即可。

  4. 服务调用

    统一采用 com.ailk.service.client.ServiceFacory 的 API,默认是基于 Hessian 实现的远程调用。

    /**
     * 服务调用
     * @param svcname
     * @param input
     * @return
     * @throws Exception
     */
    public static IDataOutput call(String svcname, IDataInput input) throws Exception
    
    /**
     * 服务调用
     * @param svcname
     * @param input
     * @param iscatch
     * @return
     * @throws Exception
     */
    public static IDataOutput call(String svcname, IDataInput input, boolean iscatch) throws Exception
    
    /**
     * 服务调用
     * @param svcname
     * @param input
     * @param pagination
     * @return
     * @throws Exception
     */
    public static IDataOutput call(String svcname, IDataInput input, Pagination pagination) throws Exception
    
    /**
     * 服务调用
     * @param svcname
     * @param input
     * @param pagination
     * @param iscatch
     * @return
     * @throws Exception
     */
    public static IDataOutput call(String svcname, IDataInput input, Pagination pagination, boolean iscatch) throws Exception
    
    /**
     * 服务调用
     * @param url
     * @param svcname
     * @param input
     * @param pagination
     * @return
     * @throws Exception
     */
    public static IDataOutput call(String url, String svcname, IDataInput input, Pagination pagination) throws Exception
    
    /**
     * 服务调用
     * @param url
     * @param svcname
     * @param input
     * @param pagination
     * @param iscatch
     * @return
     * @throws Exception 
     */
    public static IDataOutput call(String url, String svcname, IDataInput input, Pagination pagination, boolean iscatch) throws Exception
    
  5. 服务基类

    com.ailk.biz.service.BizService 结构图及 API

    /**
     * get resultcode
     */
    public String getResultCode()
    
    /**
     * set resultcode
     */
    public void setResultCode(String resultCode)
    
    /**
     * get resultinfo
     */
    public String getResultInfo()
    
    /**
     * set resultinfo
     */
    public void setResultInfo(String resultInfo)
    
    /**
     * get resultcount
     */
    public long getResultCount()
    
    /**
     * set resultcount
     */
    public void setResultCount(long resultCount)
    
    /**
     * get pagination
     */
    public Pagination getPagination()
    
    /**
     * set pagination
     */
    public void setPagination(Pagination pagination)
    
    
    /**
     * create visit
     * @param input
     * @return
     */
    public IVisit createVisit(IData head)
    
    /**
     * create pagination
     * @param head
     * @return
     */
    public Pagination createPagination(IData head)
    
    
    /**
     * get visit();
     * @return
     * @throws Exception
     */
    public static BizVisit getVisit() throws Exception
    
    
    /**
     * reate data input
     * @param params
     * @return
     */
    public static IDataInput createDataInput() throws Exception
    
    
    /**
     * create data input
     * @param params
     * @param pagin
     * @return
     */
    public static IDataInput createDataInput(IData params) throws Exception
    
    /**
     * create data input
     * @param params
     * @param pagination
     * @return
     * @throws Exception
     */
    public static IDataInput createDataInput(IData params, Pagination pagination) throws Exception
    

    示例代码:

    public class CustService extends BizService {
    	/**
    	 * query custs
    	 * @param data
    	 * @return
    	 * @throws Exception
    	 */
    	public IDataset queryCusts(IData data) throws Exception {
    		CustBean bean = BeanManager.createBean(CustBean.class);
    		return bean.queryCustsByCustName(data.getString("CUST_NAME"), getPagination());
    	}
    	
    	/**
    	 * edit cust
    	 * @param data
    	 * @return
    	 * @throws Exception
    	 */
    	public boolean editCust(IData data) throws Exception {
    		CustBean bean = BeanManager.createBean(CustBean.class);
    		return bean.updateCustName(data);
    	}
    }