java.lang.IllegalArgumentException Webservice不是接口

时间:2014-10-02 23:05:05

标签: java web-services

我已经构建了一个简单的Web服务,并且我已经成功地在apache webserver中部署了webservice并查看了WSDL。

这是我简单的网络服务 -

import javax.jws.WebMethod;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.WebParam;
import javax.jws.soap.*;


@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class HelloWebService {
    @WebMethod(operationName = "sayHello")
    public String sayHello(@WebParam(name="guestname") String guestname){
        if (guestname==null){
            return "Hello";
        }
        return "Hello "  + guestname;

    }
}

不,我试图建立一个客户端,如下所示,

public class HelloClient {
    public static void main(String[] args) throws MalformedURLException{
    URL url = new URL("http://localhost:8080/HelloWebService/helloWebService?wsdl");

    //1st argument service URI, refer to wsdl document above
//2nd argument is service name, refer to wsdl document above
    QName qname = new QName("http://demo.webservice.com/", "HelloWebServiceService");

    Service service = Service.create(url, qname);

    HelloWebService hello = service.getPort(HelloWebService.class);

    System.out.println(hello.sayHello("Hello"));
    }
}

并获得以下错误,

Exception in thread "main" java.lang.IllegalArgumentException: com.webservice.demo.HelloWebService is not an interface
    at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:624)
    at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:592)
    at java.lang.reflect.WeakCache$Factory.get(WeakCache.java:244)

1 个答案:

答案 0 :(得分:1)

正如API所述,service.getPort指定了终点接口。你正在传递一个具体的类,jre无法创建代理。有关工作示例,请参阅this(注意HelloWorld是一个接口)