一个简单的webService

1.创建接口类

@WebService
public interface Hello {
    String sayHi(@WebParam(name="name")String name);
}

2.实现接口类

@WebService(endpointInterface = "com.test.Hello",
        serviceName = "Hello")
public class HelloImpl implements Hello {
    public String sayHi(String name) {
        return "hello,"+name;
    }
}

3.发布

public class ServiceMain {

    public static void main(String[] args) throws Exception{
        System.out.print("Starting Service...");
        String address = "http://localhost:8888/hello";
        HelloImpl helloImpl = new HelloImpl();
        Endpoint.publish(address,helloImpl);
    }
}

4.访问:http://localhost:8888/hello?wsdl,如下成功

问题

执行main方法时候有可能出现以下错误,据说是JDK版本所致:

Starting Service...Exception in thread "main" com.sun.xml.internal.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class com.test.jaxws.SayHi 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:92)
    at javax.xml.ws.Endpoint.publish(Endpoint.java:170)
    at com.test.ServiceMain.main(ServiceMain.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code 1

解决方法

给接口类的sayHi()方法加上:  

@SOAPBinding(style=SOAPBinding.Style.RPC)

相关文章

1.使用ajax调用varxhr;functioninvoke(){if(window.ActiveXO...
               好不容易把WebService服务器...
1新建一个工程项目用来做服务端增加一个MyService1类文件pac...
packagecom.transsion.util;importjava.io.BufferedReader;i...
再生产wsdl文件时重写描述文件1usingSystem;2usingSystem.Co...
一般情况下,使用eclipse自带的jax-ws生成webservice会自动生...