接口:
package test;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
public String sayHello(String name);
}
实现类:
package test;
import javax.jws.WebService;
@WebService
public class HelloWorldImpl implements HelloWorld {
public String sayHello(String name) {
System.out.println("Say Hello is called");
return "--hello--"+name;
}
}
调用:
package test;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
public class MainServer {
/**
* @param args
*/
public static void main(String[] args) {
JaxWsServerFactoryBean factory =new JaxWsServerFactoryBean();
factory.setServiceClass(HelloWorldImpl.class);
factory.setAddress("http://localhost:8080/HelloWorld");
Server server =factory.create();
server.start();
}
最后这个Client ( 报错了。。。。):
package test;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
public class HelloWorldClient {
/**
* @param args
*/
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
JaxWsServerFactoryBean factory =new JaxWsServerFactoryBean();
factory.setAddress("http://localhost:8080/HelloWorld");
factory.setServiceClass(HelloWorld.class);
HelloWorld helloworld =(HelloWorld)factory.create();
System.out.println(helloworld.sayHello("AA"));
}
}
报的错是:
Exception in thread "main" java.lang.ClassCastException: org.apache.cxf.endpoint.ServerImpl cannot be cast to test.HelloWorld
at test.HelloWorldClient.main(HelloWorldClient.java:16)
WebService 异常 服务器 ?java
------解决方案--------------------