美文网首页干货-技术
CXF动态客户端在处理此问题时,会报No operation w

CXF动态客户端在处理此问题时,会报No operation w

作者: liuxliang | 来源:发表于2015-11-11 14:45 被阅读1947次

    环境:cxf  webservice 动态访问

    项目中遇到问题,后台原来用的namespace是实现方法的包名,造成一般的动态访问方式如下:

    JaxWsDynamicClientFactory dcf =JaxWsDynamicClientFactory.newInstance();

    org.apache.cxf.endpoint.Client client = dcf.createClient("http://10.71.253.165:8080/TdtSHCXF/service/cgcxf?wsdl");

    Object[] objects = null;

    try {

    objects = client.invoke("AddWxEvent", new Object[] {jsonString});

    //System.out.println(objects[0].toString());

    resp.getWriter().write(objects[0].toString());

    } catch (Exception e) {

    // TODO 自动生成的 catch 块

    e.printStackTrace();

    }

    CXF动态客户端在处理此问题时,会报No operation was found with the name的异常,所以应该用下面的代码或者把namspace变成接口的包名来解决:

    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();

    Client client = factory.createClient(url);

    //处理 WebService接口和实现类namespace不同的情况

    // CXF动态客户端在处理此问题时,会报No operation was found with the name的异常

    Endpoint endpoint = client.getEndpoint();

    QName opName = new QName(endpoint.getService().getName().getNamespaceURI(), operation(方法名));

    BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();

    if (bindingInfo.getOperation(opName) == null) {

    for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {

    if (operation.equals(operationInfo.getName().getLocalPart())) {

    opName = operationInfo.getName();

    break;}}}

    Object[] objects = null;

    try {

    objects = client.invoke(opName, new Object[] {jsonString});

    resp.getWriter().write(objects[0].toString());

    } catch (Exception e) {

    // TODO 自动生成的 catch 块

    e.printStackTrace();

    }

    相关文章

      网友评论

      • 小呆纸:operation 是什么,没有看到有声明啊。。

      本文标题:CXF动态客户端在处理此问题时,会报No operation w

      本文链接:https://www.haomeiwen.com/subject/jtuhhttx.html