user1050619
user1050619

Reputation: 20906

java.lang.IllegalArgumentException Webservice is not a interface

I have built a simple webservice and I'm successfully able to deploy the webservice in apache webserver and view the WSDL.

Here is my simple webservice -

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;

    }
}

No, Im trying to build a client as below,

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"));
    }
}

and get the below error,

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)

Upvotes: 3

Views: 8674

Answers (1)

6ton
6ton

Reputation: 4214

As the API says the service.getPort specifies the end point interface. You are passing in a concrete class, that the jre cannot create a proxy for. See this for a working example (notice that HelloWorld is an interface)

Upvotes: 1

Related Questions