首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

客户端施用AXIS2调用WebService

2013-07-16 
客户端使用AXIS2调用WebService一、单参数/** * 测试2 ** @param statistic * @param userId * @return */p

客户端使用AXIS2调用WebService

一、单参数

/** * 测试2 *  * @param statistic * @param userId * @return */public static String queryAvailableAmt() {try {targetEPR = new EndpointReference("http://192.168.10.227/ebsService/services/ebsService?wsdl");// 创建request SOAP包OMFactory fac = OMAbstractFactory.getOMFactory();// OMNamespace指定此SOAP文档名称空间OMNamespace om = fac.createOMNamespace("http://service.eee.shun.com", "client");// 创建元素,并指定其在om指代的名称空间中,元素名必须跟services.xml重大operation的name相同OMElement method = fac.createOMElement("queryAvailableAmt", om);              //下面创建的是参数对数,对应于@WebParam(name = "name")              //由于@WebParam没有指定targetNamespace,所以下面创建name参数时,用了null,否则你得赋一个namespace给它 OMElement nameElement1 = fac.createOMElement("p_dividend_date", null);              nameElement1.addChild(fac.createOMText(nameElement1, "2013-01-04"));                          OMElement nameElement2 = fac.createOMElement("p_company_code", null);              nameElement2.addChild(fac.createOMText(nameElement2, "801000"));                          OMElement nameElement3 = fac.createOMElement("p_user_name", null);              nameElement3.addChild(fac.createOMText(nameElement3, ""));                          OMElement nameElement4 = fac.createOMElement("p_password", null);              nameElement4.addChild(fac.createOMText(nameElement4, ""));                                      method.addChild(nameElement1);              method.addChild(nameElement2);              method.addChild(nameElement3);              method.addChild(nameElement4);                          Options options = new Options();              options.setTo(targetEPR);              ServiceClient sender = new ServiceClient();              sender.setOptions(options);                //下面的输出结果为<xsd:test xmlns:xsd="http://www.mycompany.com"><name>java</name></xsd:test>              System.out.println(method.toString());                //发送并得到结果,至此,调用成功,并得到了结果              OMElement result = sender.sendReceive(method);              String filePath = "E:\\queryAvailableAmt.xml";writeToFile(filePath, result);} catch (Exception e) {e.printStackTrace();}return null;}

?二、传送OMElement参数

/** * 测试1 *  * @param statistic * @param userId * @return */public static String sendDataDfzwByOMElement() {targetEPR = new EndpointReference("http://192.168.10.227/ebsService/services/ebsService?wsdl");// 创建request SOAP包OMFactory fac = OMAbstractFactory.getOMFactory();// OMNamespace指定此SOAP文档名称空间OMNamespace om = fac.createOMNamespace("http://service.eee.shun.com", "client");// 创建元素,并指定其在om指代的名称空间中,元素名必须跟services.xml重大operation的name相同OMElement method = fac.createOMElement("senddividendstrategy", om);OMElement root;OMElement svsListOmElement;List<Senddividendstrategy> svsList = new ArrayList<Senddividendstrategy>();try {Senddividendstrategy s = null;for (int i = 0; i < 10; i++) {s = new Senddividendstrategy();s.setDividend_date("2013-01-04");s.setCompany_code("2");s.setEquity_note_number("3");s.setDividend_line_number(Long.valueOf(4));s.setAssign_type_code("5");s.setAssign_source("6");s.setSegment3("7");s.setAmount(Long.valueOf(8));s.setCash_amount(Long.valueOf(9));s.setCash_proportion(Long.valueOf(10));s.setCash_person_proportion(Long.valueOf(11));s.setCapital_source("12");s.setCapital_amount(Long.valueOf(13));s.setCapital_proportion(Long.valueOf(14));s.setCapital_person_proportion(Long.valueOf(15));s.setEquity_category("16");s.setEquity_properties("17");s.setReduce_tax_amount(Long.valueOf(18));s.setStart_date("2013-01-04");s.setManager_type("20");s.setProcess_startus("21");s.setData_status("22");svsList.add(s);}root = fac.createOMElement("root", null);svsListOmElement = BeanUtil.getOMElement(new QName("sparams"), svsList.toArray(), new QName("sparam"), false, null);root.addChild(svsListOmElement);method.addChild(root);Options options = new Options();options.setTo(targetEPR);ServiceClient sender = new ServiceClient();sender.setOptions(options);// 发出request SOAP// 同时将得到的远端由senddividendstrategy方法返回的信息保存到result// 通过services.xml能准确找到senddividendstrategy方法所在的文件OMElement ome = sender.sendReceive(method);String filePath = "E:\\senddividendstrategy.xml";writeToFile(filePath, ome);} catch (Exception e) {e.printStackTrace();}return null;}

热点排行