【技术贴】webservice cxf2 客户端动态调用报错No operation was found with the name

简介: No operation was found with the name xxx 出错原因是因为发布服务的接口所在包路径和此接口实现类包路径不一致,比如你的服务接口可能放在了包com.x.interFace下,但是你的实现类却在com.

 

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

 

    
目录
相关文章
|
3月前
|
XML Java Maven
WebService客户端调用的5种常见方式
本文介绍了在Java中创建和调用WebService的方法,包括服务端的搭建、配置类的添加以及客户端的多种调用方式(如使用JDK原生代码、wsimport命令、动态调用、代理工厂及HttpClient)。文中详细展示了每种方法的实现步骤和示例代码,强调了服务端与客户端参数实体类字段的兼容性,并推荐使用代理工厂方式进行调用。
306 0
WebService客户端调用的5种常见方式
|
9月前
|
Java API Apache
Apache CXF生成WebService的客户端
Apache CXF生成WebService的客户端
282 0
|
XML Java 数据库连接
webservice客户端运行报错was not registered for synchronization because synchronization is not active
webservice客户端运行报错was not registered for synchronization because synchronization is not active
1000 0
webservice客户端运行报错was not registered for synchronization because synchronization is not active
|
安全 Java C#
【知识积累】服务器端获取客户端的IP地址(当客户端调用由Axis开发的WebService)
由于项目中一个小的模块需要获取客户端的IP地址以保证安全调用webservice接口,项目中客户端使用C#编写,服务器端使用Java编写,服务器端与客户端采用Axis开发的WebService进行通信。服务器端维护IP白名单列表,只有IP地址在白名单中的客户端才可以成功调用到接口,获得服务。
273 0
|
Python
MODIS数据的简介和下载(番外篇)——MODIS Web Service的Python客户端应用
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ESA_DSQ/article/details/79096167 新年开坑第一篇,关于之前MODIS系列博客的补充和番外篇。
1624 0
|
Java Android开发
Eclipse 生成WebService客户端代码
1. 打开Eclipse,新建一个普通的Java project,然后在新建的项目上右键点击项目,New---->other---->Web Services -------->Web Service Client       2.
2771 0
|
Java
Web service 客户端 应用
试了好多方法(如axis2、xfire),一直报错,后来才知道用java的基础包就可以。汗~~ 来贴上代码吧   1 import javax.jws.WebMethod; 2 import javax.
1114 0
|
SQL Java 数据库
Android通过webservice连接SQLServer 详细教程(数据库+服务器+客户端)
出处 http://blog.csdn.net/zhyl8157121/article/details/8169172 其实之前发过一篇这样的博文http://blog.
1496 0
|
PHP
php调用webservice报错Class 'SoapClient' not found
原文: php调用webservice报错Class 'SoapClient' not found       php在调用webservice时,报告如下类似错误:            ( ! ) Fatal error: Class 'SoapCl...
1137 0