使用CXF动态客户端No operation was found with the name异常

在使用如下CXF动态的时候,创建客户端的时候报错No operation was found with the name

客户端


package com.p.dynamic.client;
import javax.xml.namespace.QName;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;


 */
public final class ComplexClient {
 public static void main(String[] args) throws Exception {
    QName SERVICE_NAME = new QName("http://com.p.service/", "sayHi");
    String wsdlURL = "http://localhost:9000/Complex?wsdl";   
    
    //JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
    //Client client = factory.createClient(wsdlURL,SERVICE_NAME ); //报错
    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
    Client client = factory.createClient(wsdlURL); 
    Object[] result = client.invoke(SERVICE_NAME,"调用大数据"); //报错
 }
}

在客户端启动的时候报错No operation was found with the name。检查原因是因为CXF默认取的是接口类所在路径作为命名空间,一般问题出在接口上,下面是接口

 

接口 

package com.p.service;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface HelloWorld {
    @WebMethod
    String sayHi(String text);

}

看到因为,因为在client动态调用的时候,    QName SERVICE_NAME = new QName("http://com.p.service/", "sayHi"); 使用的是

http://com.p.service/

而正确的应该是,

“http://service.p.com/”

。为了出现其他问题,应该再添加

        endpointInterface="com.yuepai.service.HelloWorld",
        targetNamespace="http://com.yuepai.service"

如下:

package com.yuepai.service;

import javax.jws.WebMethod;
import javax.jws.WebService;

import org.w3c.dom.Document;

		
@WebService(
		endpointInterface="com.p.service.HelloWorld",
		targetNamespace="http://com.p.service")
public interface HelloWorld {
    @WebMethod
    String sayHi(String text);

}

启动服务

package com.yuepai.dynamic.server;

import javax.xml.ws.Endpoint;
import com.p.service.impl.HelloWorldImpl;

public class Server {

    protected Server() throws Exception {
        System.out.println("Starting Server");
        HelloWorldImpl complexImpl = new HelloWorldImpl();
        String address = "http://localhost:9000/Complex";
        Endpoint.publish(address, complexImpl);
    }

    public static void main(String args[]) throws Exception {
        new Server();
        System.out.println("Server ready...");

        Thread.sleep(5 * 60 * 1000);
        System.out.println("Server exiting");
        System.exit(0);
    }
}

 

实现类

package com.p.service.impl;
import com.p.service.HelloWorld;

public class HelloWorldImpl implements HelloWorld {

    public String sayHi(String text) {
        System.out.println("sayHi called");
        return "Hello " + text;
    }
}

 

转载于:https://my.oschina.net/jywm/blog/698687

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值