【技术贴】webservice cxf2 客户端动态调用报错No operation was found with the name
No operation was found with the name xxx
出错原因是因为发布服务的接口所在包路径和此接口实现类包路径不一致,比如你的服务接口可能放在了包com.x.interFace下,但是你的实现类却在com.x.interFace.impl包下,此时,发布的服务被客户端动态调用(JaxWsDynamicClientFactory)的时候,就会报错:
org.apache.cxf.common.i18n.UncheckedException: No operation was found with the name {http://impl.server.test.com/}xxxx.
就是说找不到某个方法
解决办法也很简单:直接在你的实现类上,加上注解:targetNamespace = "http://service.webservice.com/",这个包名(服务接口所在的包名)反写
如下:
我的实现类包名是com.webservice.service.impl
我的服务接口包名:com.webservice.service
所以 targetNamespace要写成我的服务接口所在包名的反写
@WebService(endpointInterface = "com.webservice.service.Server1", serviceName = "server1", targetNamespace = "http://service.webservice.com/") public class Server1Impl implements Server1 { public String getInfo(String name, int age) { return name.concat(",Hello Word! ! " + name + " age: " + age); } public static void main2(String[] args) { Server1Impl serverImpl = new Server1Impl(); JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean(); factory.setServiceClass(Server1.class); factory.setAddress("http://localhost:1111/server1"); factory.setServiceBean(serverImpl); factory.getInInterceptors().add(new LoggingInInterceptor()); factory.getInInterceptors().add(new LoggingOutInterceptor()); factory.create(); } }
以下摘自:http://www.cnblogs.com/yshyee/p/3633537.html
信息: Created classes: com.test.server.HelloWorld, com.test.server.HelloWorldResponse, com.test.server.ObjectFactory Exception in thread "main" org.apache.cxf.common.i18n.UncheckedException: No operation was found with the name {http://impl.server.test.com/}helloWorld. at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:342) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:336) at com.test.client.HelloWorl.main(HelloWorl.java:20) Java Result: 1
解决方法:对服务端的接口实现类中的@WebService添加targetNamespace,其值为接口包名的倒置,
例如我的IHelloWorld接口所在的包为com.test.server,此时对应的targeNamespace的值为http://server.test.com/
例如:
@WebService( endpointInterface = "com.test.server.IHelloWorld", serviceName="helloWorld", targetNamespace="http://server.test.com/") public class HelloWorldImp implements IHelloWorld { public String helloWorld(String name) { return name+" Hello,World!"; }