webservice(一) 初涉

來源:互聯網
上載者:User

標籤:

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版本以上;

定義介面方法: @WebServicepublic 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個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.