我已经构建了一个简单的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)