一:IDE(MyEclipse)中以JAX-WS框架开启WebProject中服务类的WebService服务接口,自动生成额外代码:
1,服务类的webservice代理类,可以指定namespace
//服务类: public class WsClass6 { public ResEntity wsmethod1( ReqEntity param ){ ResEntity rstmp = new ResEntity(); String tmpa = param.getRqa() + "(wsmethod1)"; int tmpb = param.getRqb() + 1; rstmp.setRsa(tmpb); rstmp.setRsb(tmpa); return rstmp; } } //生成服务代理类: @javax.jws.WebService(targetNamespace = "http://x.y.z/c6/", serviceName = "WsClass6Service", portName = "WsClass6Port", wsdlLocation = "WEB-INF/wsdl/WsClass6Service.wsdl") public class WsClass6Delegate { com.test6.WsClass6 wsClass6 = new com.test6.WsClass6(); public ResEntity wsmethod1(ReqEntity param) { return wsClass6.wsmethod1(param); } }
2,sun-jaxws.xml 配置endpoint
sun-jaxws.xml 配置
<?xml version = "1.0"?> <endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"> <endpoint name="WsClass6Port" implementation="com.test6.WsClass6Delegate" url-pattern="/WsClass6Port"> </endpoint> <endpoint name="WsClass62Port" implementation="com.test6.WsClass62Delegate" url-pattern="/WsClass62Port"> </endpoint> </endpoints>
3,web.xml中Servlet、listener配置
web.xml配置
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <description>JAX-WS endpoint - WsClass6Service</description> <display-name>WsClass6Service</display-name> <servlet-name>WsClass6Service</servlet-name> <servlet-class> com.sun.xml.ws.transport.http.servlet.WSServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>WsClass6Service</servlet-name> <url-pattern>/WsClass62Port</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>WsClass6Service</servlet-name> <url-pattern>/WsClass6Port</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <listener> <listener-class> com.sun.xml.ws.transport.http.servlet.WSServletContextListener </listener-class> </listener> </web-app>
目录结构:
WEB-INF/
--------web.xml
--------sun-jaxws.xml
--------wsdl/
------------WsClass6Service.wsdl
------------WsClass6Service_schema1.xsd
二:IDE中以JAX-WS框架生成客户端
可以用IDE,以WSDL文件或者WSDL URL文件方式生成客户端代码;
src/
-------ObjectFactory.java
-------package-info.java
-------ReqEntity.java
-------ResEntity.java
-------WsClass6Delegate.java
-------WsClass6Service.java
-------Wsmethod1.java
-------Wsmethod1Response.java
三:调用WebService客户端
//客户端调用: public class Testws6client6 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub WsClass6Service ws = new WsClass6Service(); ReqEntity rq = new ReqEntity(); rq.setRqa("December"); rq.setRqb(1); ResEntity rs = ws.getWsClass6Port().wsmethod1(rq); System.out.println(rs.getRsa() + " , " + rs.getRsb()); } }
四:在tomcat(6.0)运行环境部署WebService project时需要的一些jar包
gmbal-api-only.jar
,ha-api.jar
,javax.annotation-api.jar
,javax.xml.soap-api.jar
,jaxb-api.jar
,jaxb-core.jar
,jaxb-impl.jar
,jaxws-api.jar
,jaxws-rt.jar
,jaxws-tools.jar
,management-api.jar
,policy.jar
,stax-ex.jar
,streambuffer.jar