【技術貼】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!";    }

 

    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM