1、第三方调用 U9 服务(Java 平台)一、 Java 环境搭建a) Jdk版本 jdk-5_5_0_10b) apache-cxf-2.2.4c) 开发工具 Eclipsed) 配置环境变量添加新变量 ClASSPATH: 值为“.;C:Program FilesJavajdk1.5.0_10libTools.jar;C:Program FilesJavajdk1.5.0_10jrelibrt.jar”添加新变量 Java_HOME :值为“C:Program FilesJavajdk1.5.0_10”Path变量后追加: “C:Program FilesJavajdk1.5.0_10bin
2、”说明:C:Program FilesJavajdk1.5.0_10 是 jdk的安装目录e) UFIDA U9服务器 二、 引用 U9 服务以创建收货单服务为例, UFIDA.U9.ISV.RCV.ICreateRCVSRV.svca) 验证服务是否可用如果能显示显示下面的图片说明服务可用b) 生成代理类利用 apache-cxf-2.2.4 针对 wsdl 导出 java 客户端文件D:apache-cxf-2.2.4bin wsdl2java -d d:JavaService -verbose http:/localhost/portal/services/UFIDA.U9.ISV.RC
3、V.ICreateRCVSRV.svc?wsdl注明:-d -verbose查看生成的文件:c) 构架项目1. 创建 Java 测试工程2. Copy cxf 生成客户端 Java 文件到工程目录3. 新建类 TestMain.java4. 添加外部引用库 Jar在项目上右键点属性5. 修改服务地址 Uri三、 项目实现细节a) 调用服务框架代码类似DotNet平台调用代码,主要是语法不同/开始调用ERP服务,“创建服务”org.tempuri.CreateRCVSRVStub createRcvsvclient = new org.tempuri.CreateRCVSRVStub();org
4、.ufida.UFIDAU9ISVRCVICreateRCVSRV createsv = createRcvsvclient.getBasicHttpBindingUFIDAU9ISVRCVICreateRCVSRV();/给头、明细赋值org.ufida.entitydata.ArrayOfUFIDAU9ISVRCVDTOOBAReceivementDTOData rCVList = createRCVList();/doResult就是返回结果。Holder doResult = new Holder() ;Holder outMessages = new Holder(); try/将入
5、库单内容传入ERP(入和返的值,均作为此方法的参数)。/context验证信息,rCVList入的值,doResult 方法返回值, createsv._do(context, rCVList, doResult, outMessages);System.out.println(“Invoke end .“);catch(Exception ex)/省略部分代码b) 上下文信息/创建当前上下文(相当于验证信息,这部分需灵活配置)String IDForCompany = “002“;/当前企业编号Long IDForOrganization = new Long(“10010071289610
6、46“);/当前组织IDLong IDForUsers = new Long(“1001007176447429“);/当前用户IDString UserCode = “demo“;/当前用户编码/创建上下文环境Object context = createContext(IDForCompany,IDForOrganization,IDForUsers,UserCode);/创建上下文环境 private static Object createContext(String entid,long orgid,long userid,String usercode) org.datacontr
7、act.schemas._2004._07.ufsoft_ubf_util.ObjectFactory contextfactory = new org.datacontract.schemas._2004._07.ufsoft_ubf_util.ObjectFactory();org.datacontract.schemas._2004._07.ufsoft_ubf_util.ThreadContext tc = contextfactory.createThreadContext();com.microsoft.schemas._2003._10.serialization.arrays.
8、ObjectFactory arrayFactory = new com.microsoft.schemas._2003._10.serialization.arrays.ObjectFactory();ArrayOfKeyValueOfanyTypeanyType contextarray = arrayFactory.createArrayOfKeyValueOfanyTypeanyType();KeyValueOfanyTypeanyType kv1 = new KeyValueOfanyTypeanyType();kv1.setKey(“EnterpriseID“);kv1.setVa
9、lue(entid);/填具体的企业编号contextarray.getKeyValueOfanyTypeanyType().add(kv1);KeyValueOfanyTypeanyType kv2 = new KeyValueOfanyTypeanyType();kv2.setKey(“OrgID“);kv2.setValue(orgid);/填具体的组织IDcontextarray.getKeyValueOfanyTypeanyType().add(kv2);KeyValueOfanyTypeanyType kv3 = new KeyValueOfanyTypeanyType();kv3
10、.setKey(“UserID“);kv3.setValue(userid);/填具体的用户IDcontextarray.getKeyValueOfanyTypeanyType().add(kv3);KeyValueOfanyTypeanyType kv4 = new KeyValueOfanyTypeanyType();kv4.setKey(“UserCode“);kv4.setValue(usercode);/填具体的用户编码contextarray.getKeyValueOfanyTypeanyType().add(kv4);KeyValueOfanyTypeanyType kv5 =
11、new KeyValueOfanyTypeanyType();kv5.setKey(“CultureName“);kv5.setValue(“zh-CN“);/当前语种contextarray.getKeyValueOfanyTypeanyType().add(kv5);tc.setNameValueHas(contextarray);return tc ;c) 传入参数private static org.ufida.entitydata.ArrayOfUFIDAU9ISVRCVDTOOBAReceivementDTOData createRCVList()org.ufida.entityd
12、ata.ObjectFactory dataFactory = new org.ufida.entitydata.ObjectFactory();/创建DTO集合,也就是参数要求的对象。org.ufida.entitydata.ArrayOfUFIDAU9ISVRCVDTOOBAReceivementDTOData rcvDToArray = dataFactory.createArrayOfUFIDAU9ISVRCVDTOOBAReceivementDTOData();/DTO集合中的每个对象,都需要这样创建出来。UFIDAU9ISVRCVDTOOBAReceivementDTOData h
13、eaderData = dataFactory.createUFIDAU9ISVRCVDTOOBAReceivementDTOData();/ 表头赋值headerData.setSysState(ObjectState.INSERTED);/“新建”标记符XMLGregorianCalendar timeValue = new XMLGregorianCalendarImpl();timeValue.setYear(2010); timeValue.setMonth(4); timeValue.setDay(2); timeValue.setHour(10);timeValue.setMin
14、ute(35);timeValue.setSecond(30);headerData.setMBusinessDate(timeValue); / 日期/单据类型 UFIDAU9PMDTOsBESimp4UIDTOData docType = dataFactory.createUFIDAU9PMDTOsBESimp4UIDTOData();docType.setMCode(dataFactory.createUFIDAU9PMDTOsBESimp4UIDTODataMCode(“RCV01“);docType.setSysState(ObjectState.INSERTED);headerD
15、ata.setMRcvDocType( dataFactory.createUFIDAU9ISVRCVDTOOBAReceivementDTODataMRcvDocType(docType);。/省略部分代码/对明细进行赋值UFIDAU9ISVRCVDTOOBARcvLineDTOData detailsData = dataFactory.createUFIDAU9ISVRCVDTOOBARcvLineDTOData();detailsData.setSysState(ObjectState.INSERTED);detailsData.setMDocLineNo(10);/行号/料品UFID
16、AU9CBOSCMItemItemInfoData ItemInfoData = dataFactory.createUFIDAU9CBOSCMItemItemInfoData();ItemInfoData.setMItemCode(dataFactory.createUFIDAU9CBOSCMItemItemInfoDataMItemCode(“1-01-0“);ItemInfoData.setSysState(ObjectState.INSERTED);detailsData.setMItemInfo(dataFactory.createUFIDAU9ISVRCVDTOOBARcvLine
17、DTODataMItemInfo(ItemInfoData);/料品/最终价BigDecimal finallyPrice = new BigDecimal(“3200“);detailsData.setMFinallyPriceTC(finallyPrice);。/省略部分代码/将明细的值放入头中ArrayOfUFIDAU9ISVRCVDTOOBARcvLineDTOData m_m_detail = dataFactory.createArrayOfUFIDAU9ISVRCVDTOOBARcvLineDTOData();m_m_detail.getUFIDAU9ISVRCVDTOOBARc
18、vLineDTOData().add(detailsData);headerData.setMRcvLines(dataFactory.createUFIDAU9ISVRCVDTOOBAReceivementDTODataMRcvLines(m_m_detail);/注意:任何参数的类型只要不是最简单类型,都应该通过 Factory来创建。/一般这个类型在哪个包中,Facotry 也会在同样的包中有一个 ObjectFacotry的类型rcvDToArray.getUFIDAU9ISVRCVDTOOBAReceivementDTOData().add(headerData);return rc
19、vDToArray;d) 捕获异常/捕获服务中的异常。catch(org.ufida.UFIDAU9ISVRCVICreateRCVSRVDoServiceExceptionFaultFaultMessage ex)/下面的代码可以将服务端的异常信息给显示输出来。ServiceException ed = ex.getFaultInfo();for (int i=0 ;ied.getAny().size()-1;i+)System.out.println(ed.getAny().get(i).toString(); System.out.println(ed.getAny().get(i).getFirstChild().toString(); catch(Exception ex)System.out.println(“Error.“);System.out.println(ex.getMessage();System.out.println(ex.getClass().toString();System.out.println(ex.getStackTrace().toString();
Copyright © 2018-2021 Wenke99.com All rights reserved
工信部备案号:浙ICP备20026746号-2
公安局备案号:浙公网安备33038302330469号
本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。