首页 > 代码库 > webservice(一) 初涉
webservice(一) 初涉
Exception in thread "main" com.sun.xml.internal.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class com.wa.jaxws.SayHello is not found. Have you run APT to generate them? at com.sun.xml.internal.ws.model.RuntimeModeler.getClass(RuntimeModeler.java:256) at com.sun.xml.internal.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:567) at com.sun.xml.internal.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:514) at com.sun.xml.internal.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:341) at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:227) at com.sun.xml.internal.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:308) at com.sun.xml.internal.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:174) at com.sun.xml.internal.ws.api.server.WSEndpoint.create(WSEndpoint.java:420) at com.sun.xml.internal.ws.api.server.WSEndpoint.create(WSEndpoint.java:439) at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.createEndpoint(EndpointImpl.java:208) at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:138) at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:90) at javax.xml.ws.Endpoint.publish(Endpoint.java:170) at com.wa.ServerTest.main(ServerTest.java:9)
原因
cxf需要jaxws-api-2.1.jar及jaxb-api-2.1.jar的支持。
解决办法
1. 检查项目里是否有上述相关Jar包,如果没有,将cxf所需的2.1的jar复制一份到jdk目录下的jre\lib\endorsed文件夹中。如果endorsed文件夹不存在,可新建。
2. 项目里是有上述相关Jar包,还需要在public class XXX类上方加入@SOAPBinding(style = SOAPBinding.Style.RPC);
3. JDK升级到1.6.0.22版本以上;
定义接口方法: @WebService public interface HelloInt { @WebMethod public String sayHello(String name ); } 定义实现类: @WebService @SOAPBinding(style = SOAPBinding.Style.RPC) public class HelloImpl implements HelloInt { @Override public String sayHello(String name) { return "hello,"+name; } } 测试方法: public class ServerTest { public static void main(String[] args) { String address = "http://192.168.1.100:8989/d01ws/hello"; Endpoint.publish(address,new HelloImpl()); System.out.println("webservice发布成功"); } }
运行程序:
在浏览器地址栏输入:http://192.168.1.100:8989/d01ws/hello?wsdl
可以看到内容,发布成功:
<?xml version="1.0" encoding="UTF-8"?> @namespace html url(http://www.w3.org/1999/xhtml); :root { font:small Verdana; font-weight: bold; padding: 2em; padding-left:4em; } * { display: block; padding-left: 2em; } html|style { display: none; } html|span, html|a { display: inline; padding: 0; font-weight: normal; text-decoration: none; } html|span.block { display: block; } *[html|hidden], span.block[html|hidden] { display: none; } .expand { display: block; } .expand:before { content: ‘+‘; color: red; position: absolute; left: -1em; } .collapse { display: block; } .collapse:before { content: ‘-‘; color: red; position: absolute; left:-1em; } <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI‘s version is JAX-WS RI 2.1.1 in JDK 6. --> <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI‘s version is JAX-WS RI 2.1.1 in JDK 6. --> <definitions name="HelloImplService" targetNamespace="http://wa.com/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://wa.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"><?XML:NAMESPACE PREFIX = [default] http://schemas.xmlsoap.org/wsdl/ NS = "http://schemas.xmlsoap.org/wsdl/" /><types/><message name="sayHello"><part name="arg0" type="xsd:string"/></message><message name="sayHelloResponse"><part name="return" type="xsd:string"/></message><portType name="HelloImpl"><operation name="sayHello" parameterOrder="arg0"><input message="tns:sayHello"/><output message="tns:sayHelloResponse"/></operation></portType><binding name="HelloImplPortBinding" type="tns:HelloImpl"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="sayHello"><soap:operation soapAction=""/><input><soap:body namespace="http://wa.com/" use="literal"/></input><output><soap:body namespace="http://wa.com/" use="literal"/></output></operation></binding><service name="HelloImplService"><port name="HelloImplPort" binding="tns:HelloImplPortBinding"><soap:address location="http://192.168.1.110:8989/d01ws/hello"/></port></service></definitions>
webservice(一) 初涉
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。