关于使用wsdl 的 Web Service项目

 1.Service类

  
  
  
  
  1. package com.zhao.grgroup.ws;
  2. @WebService 
  3. @SOAPBinding(style=SOAPBinding.Style.RPC) 
  4. public class Service { 
  5.     @Resource  
  6.     WebServiceContext wsContext; 
  7.     static Logger logger = Logger.getLogger(Service.class); 
  8.     /** 卸货委托书接收 
  9.      * @param xhwtsHeader 抬头部分 
  10.      * @param xhwtsItems  项目部分 
  11.      * @return 字符串 S 表示成功 
  12.      */ 
  13.     @WebMethod(operationName = "xhwts")  
  14.     public String xhwts(@WebParam(name = "jcwtHeader")XhwtsHeaderBean[] xhwtsHeader, 
  15.             @WebParam(name = "jcwtItems")XhwtsItemBean[] xhwtsItems){ 
  16. //do things

2.各种JavaBean类

包含属性和对应的getter、setter

3.设置项目的WEB-INF的sun-jaxws.xml

 

  
  
  
  
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"> 
  3.  <endpoint   
  4.         name="Service"   --name
  5.         implementation="com.zhao.grgroup.ws.Service"  --完整的包名+类名 
  6.         url-pattern="/export"  --访问路径(跟web.xml中的一致)
  7.  />   
  8. <endpoint   
  9.         name="TcpsService"   
  10.         implementation="com.zhao.grgroup.ws.tcps.Service"   
  11.         url-pattern="/tcps-export" 
  12.  />  
  13. </endpoints> 

4.设置项目的web.xml

  
  
  
  
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
  3.     <display-name>grgroup-ws</display-name> 
  4.     <welcome-file-list> 
  5.         <welcome-file>index.html</welcome-file> 
  6.         <welcome-file>index.htm</welcome-file> 
  7.         <welcome-file>index.jsp</welcome-file> 
  8.         <welcome-file>default.html</welcome-file> 
  9.         <welcome-file>default.htm</welcome-file> 
  10.         <welcome-file>default.jsp</welcome-file> 
  11.     </welcome-file-list> 
  12.      
  13.     <context-param> 
  14.       <param-name>ProxoolConfigFile</param-name> 
  15.       <param-value>/WEB-INF/proxool.config</param-value> 
  16.     </context-param> 
  17.     <listener> 
  18.         <listener-class>com.zhao.common.db.ProxoolListener</listener-class> 
  19.     </listener> 
  20.      
  21.     <listener> 
  22.         <listener-class>com.zhao.common.ConfigListener</listener-class> 
  23.     </listener> 
  24.  
  25.     <listener> 
  26.         <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class> 
  27.     </listener> 
  28.     <servlet> 
  29.         <servlet-name>jax-ws</servlet-name> 
  30.         <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> 
  31.         <load-on-startup>1</load-on-startup> 
  32.     </servlet> 
  33.     <servlet-mapping> 
  34.         <servlet-name>jax-ws</servlet-name> 
  35.         <url-pattern>/export</url-pattern> 
  36.     </servlet-mapping>    
  37.      
  38.     <servlet> 
  39.         <servlet-name>jax-ws-tcps</servlet-name> 
  40.         <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> 
  41.         <load-on-startup>1</load-on-startup> 
  42.     </servlet> 
  43.     <servlet-mapping> 
  44.         <servlet-name>jax-ws-tcps</servlet-name> 
  45.         <url-pattern>/tcps-export</url-pattern> 
  46.     </servlet-mapping>   
  47. </web-app> 

5.使用apache-cxf-2.7.0生成web service的client端访问类

  
  
  
  
  1. 1.进入目录 :  
  2. D:\zhao\jee-juno\apache-cxf-2.7.0\bin 
  3.  
  4. 2.执行命令,获得client端代码 
  5. D:\zhao\jee-juno\apache-cxf-2.7.0\bin>wsdl2java -client -encoding utf-8 -d D:\zhao\jee-juno\export(生成类的保存路径) http://localhost:8080/grgroup-ws/export?wsdl 
  6.  
  7. 3.client调用server 
  8. Service_ServicePort_Client.java 

6.client访问service

 

  
  
  
  
  1. public static void main(String args[]) throws java.lang.Exception { 
  2.         URL wsdlURL = ServiceService.WSDL_LOCATION; 
  3.         if (args.length > 0 && args[0] != null && !"".equals(args[0])) {  
  4.             File wsdlFile = new File(args[0]); 
  5.             try { 
  6.                 if (wsdlFile.exists()) { 
  7.                     wsdlURL = wsdlFile.toURI().toURL(); 
  8.                 } else { 
  9.                     wsdlURL = new URL(args[0]); 
  10.                 } 
  11.             } catch (MalformedURLException e) { 
  12.                 e.printStackTrace(); 
  13.             } 
  14.         } 
  15.        
  16.         //wsdlURL可配置 
  17.         //port可以循环利用? 
  18.         ServiceService ss = new ServiceService(wsdlURL, SERVICE_NAME); 
  19.         Service port = ss.getServicePort(); 
  20.  
  21.  
  22.         System.out.println("Invoking tzckd..."); 
  23.         com.pansontech.grgroup.ws.TzckdHeaderBeanArray _tzckd_tzckdHeader = null
  24.         _tzckd_tzckdHeader = new TzckdHeaderBeanArray(); 
  25.         TzckdHeaderBean tableSapDrumHeavyOut = new TzckdHeaderBean(); 
  26.         //基本信息 
  27.         tableSapDrumHeavyOut.setDjh("d"); 
  28.         tableSapDrumHeavyOut.setZdrq("1900-4-1 00:00:05"); 
  29.         tableSapDrumHeavyOut.setTzckdh("t"); 
  30.         tableSapDrumHeavyOut.setCzck("c"); 
  31.         tableSapDrumHeavyOut.setCzckms("c"); 
  32.         tableSapDrumHeavyOut.setGc("c"); 
  33.         tableSapDrumHeavyOut.setGcms("c"); 
  34.         tableSapDrumHeavyOut.setXsddh("c"); 
  35.         tableSapDrumHeavyOut.setSjxm("c"); 
  36.         tableSapDrumHeavyOut.setSjsfz("c"); 
  37.         tableSapDrumHeavyOut.setThdw("c"); 
  38.         tableSapDrumHeavyOut.setCh("c"); 
  39.         tableSapDrumHeavyOut.setBz("c"); 
  40.         tableSapDrumHeavyOut.setShdz("c"); 
  41.         _tzckd_tzckdHeader.getItem().add(tableSapDrumHeavyOut); 
  42.         com.pansontech.grgroup.ws.TzckdItemBeanArray _tzckd_tzckdItems = null
  43.         _tzckd_tzckdItems = new TzckdItemBeanArray(); 
  44.         TzckdItemBean tableSapDrumHeavyOutDetail = new TzckdItemBean( ); 
  45.         tableSapDrumHeavyOutDetail.setDjh("d"); 
  46.         tableSapDrumHeavyOutDetail.setXmh("x"); 
  47.         tableSapDrumHeavyOutDetail.setWlh("w"); 
  48.         tableSapDrumHeavyOutDetail.setWlms("w"); 
  49.         tableSapDrumHeavyOutDetail.setJhsl("1"); 
  50.         tableSapDrumHeavyOutDetail.setJbjldw("2"); 
  51.         tableSapDrumHeavyOutDetail.setKcdd("k"); 
  52.         tableSapDrumHeavyOutDetail.setGg("3"); 
  53.          
  54.         _tzckd_tzckdItems.getItem().add(tableSapDrumHeavyOutDetail); 
  55.          
  56.         tableSapDrumHeavyOutDetail = new TzckdItemBean( ); 
  57.         tableSapDrumHeavyOutDetail.setDjh("d"); 
  58.         tableSapDrumHeavyOutDetail.setXmh("x"); 
  59.         tableSapDrumHeavyOutDetail.setWlh("w"); 
  60.         tableSapDrumHeavyOutDetail.setWlms("w"); 
  61.         tableSapDrumHeavyOutDetail.setJhsl("1"); 
  62.         tableSapDrumHeavyOutDetail.setJbjldw("2"); 
  63.         tableSapDrumHeavyOutDetail.setKcdd("k"); 
  64.         tableSapDrumHeavyOutDetail.setGg("3"); 
  65.          
  66.         _tzckd_tzckdItems.getItem().add(tableSapDrumHeavyOutDetail); 
  67.         java.lang.String _tzckd__return = port.tzckd(_tzckd_tzckdHeader, _tzckd_tzckdItems); 
  68.         System.out.println("tzckd.result=" + _tzckd__return); 
  69.  
  70.  
  71. }         

 

你可能感兴趣的:(Web,wsdl,service,的)