`
Donald_Draper
  • 浏览: 950221 次
社区版块
存档分类
最新评论

No operation was found with the name解决方法总结

阅读更多
CXF动态客户端总是提示No operation was found with the name {...},命名空间问题:
http://pangsir.iteye.com/blog/1492508
当我们使用CXF动态客户端调用WebService接口容易出现如下问题:
Exception in thread "main" org.apache.cxf.common.i18n.UncheckedException: No operation was found with the name {http://impl.service.jws/}sum.
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:289)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:283)
	at cxf.bootstrap.CxfDynamicClientOnJwsRtWeb.main(CxfDynamicClientOnJwsRtWeb.java:36)

这个问题是由这个问题因为SIB和SEI类的targetNamespace统一导致的,解决方法
SIB的targetNamespace的命名空间为SEI对应的命名空间targetNamespace相同即可。
1.第一种方式为配置SIB和SEI的targetNamespace相同:
SIB:
package jws.service.impl;

import javax.jws.WebService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import entity.User;
import jws.service.JwsIService;
/**
 * Service implementation Bean(SIB)
 * RPC接口实现
 * 注意这里的targetNamespace的命名空间为SEI对应的命名空间,注意最后要加/
 * 否则利用CXF动态客户端调用时,会找不到
 * Exception in thread "main" org.apache.cxf.common.i18n.UncheckedException: 
 * No operation was found with the name {http://impl.service.jws/}sum.
 * @author donald
 * 2017年7月7日
 * 下午5:11:49
 */
@WebService(endpointInterface="jws.service.JwsIService",
        serviceName = "jwsService", 
        portName = "jwsPort",
        targetNamespace = "http://service.jws/"
//        targetNamespace = "http://www.donald.service/jws_service/"
    )
public class JwsServiceImpl implements JwsIService {
private static final Logger log = LoggerFactory.getLogger(JwsServiceImpl.class);
	@Override
	public int sum(int firstNum, int secondNum) {
		int result = firstNum+secondNum;
		log.info("======"+firstNum+"+"+secondNum+"="+result);
		return result;
	}
}

SEI:
package jws.service;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

import entity.User;
/**
 * service endpoint interface(SEI)
 * RPC接口
 * 如果返回结果时实例类,则targetNamespace必须用http://service.jws/,即http://+SEI倒序报名+/
 * 没有的话可以,targetNamespace可任意指定http://www.donald.service/jws_service/
 * @author donald
 * 2017年7月7日
 * 下午5:11:53
 */
@WebService(
		targetNamespace = "http://service.jws/"
//		targetNamespace = "http://www.donald.service/jws_service/"
		)
public interface JwsIService {
	//@WebMethod注解可写可不写
//	@WebMethod 
	@WebResult(name="sumResult")
	public int sum(@WebParam(name="firstNum")int firstNum,
			@WebParam(name="secondNum")int secondNum);
	
}

SIB和SEI的@WebService注解中的targetNamespace要相同,
SIB的@WebService的targetNamespace对应为SEI的targetNamespace。

动态客户端:
package cxf.bootstrap;


import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jws.service.User;
import util.JsonUtil;

/**
 * CXF 动态代理模式,不用生成本地WS代理类,
 * 通过反射调用 WS 的对应的方法,传入相应的参数
 * 访问cxf-server-web项目下的webservice;
 * 测试jaxws-rt发布WebService web方式。
 * 此测试实例,用于测试SEI和SIB的targetNamespace指定的webService接口:
 * http://localhost:8080/cxf_server_web/jws_services?wsdl;
 * @author donald
 * 2017年7月8日
 * 下午7:24:12
 */
public class CxfDynamicClientOnJwsRtWeb {
	private static final Logger log = LoggerFactory.getLogger(CxfClient.class);
	private static final String JWS_RT_WSDL_URI = "http://localhost:8080/cxf_server_web/jws_services?wsdl";
	public static void main(String[] args) throws Exception {
		log.info("======CXF-WS Dynamic Client start!======");
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		Client client =  dcf.createClient(JWS_RT_WSDL_URI);
		HTTPConduit conduit = (HTTPConduit)client.getConduit(); 
		HTTPClientPolicy policy = new HTTPClientPolicy(); 
		policy.setConnectionTimeout(10000); 
		policy.setAllowChunking(false); 
		policy.setReceiveTimeout(10000); 
		conduit.setClient(policy);	
		Object[] invokeResult = client.invoke("sum", 17,8);
		log.info("=======sumResult:" + invokeResult[0]);
	}
}

2.第二种方式动态客户端直接通过QName调用WebService对应的操作,
这种方式针对SIB和SEI的targetNamespace不相同,同时不再同一个包:

动态客户端:
package cxf.bootstrap;

import javax.xml.namespace.QName;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.service.model.BindingInfo;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jws.service.User;
import util.JsonUtil;

/**
 * CXF 动态代理模式,不用生成本地WS代理类,
 * 通过反射调用 WS 的对应的方法,传入相应的参数
 * 访问cxf-server-web项目下的webservice;
 * 测试jaxws-rt发布WebService web方式。
 * 此测试实例,用于测试SEI和SIB的targetNamespace未指定的webService接口:
 * http://localhost:8080/cxf_server_web/jws_services?wsdl
 * @author donald
 * 2017年7月8日
 * 下午7:24:12
 */
public class CxfDynamicClientOnJwsRtWebWithQname {
	private static final Logger log = LoggerFactory.getLogger(CxfClient.class);
	private static final String JWS_RT_WSDL_URI = "http://localhost:8080/cxf_server_web/jws_services?wsdl";
	public static void main(String[] args) throws Exception {
		log.info("======CXF-WS Dynamic Client start!======");
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		Client client =  dcf.createClient(JWS_RT_WSDL_URI);
		HTTPConduit conduit = (HTTPConduit)client.getConduit(); 
		HTTPClientPolicy policy = new HTTPClientPolicy(); 
		policy.setConnectionTimeout(10000); 
		policy.setAllowChunking(false); 
		policy.setReceiveTimeout(10000); 
		conduit.setClient(policy);	
		//获取操作对应的Qname
		QName operateQName = getOperateQName(client,"sum");
		//如果Qname已知,可以通过如下方式,直接创建QName
//		operateQName = new QName("http://service.jws/","login");
		Object[] invokeResult = client.invoke(operateQName, 17,8);	
		log.info("=======sumResult:" + invokeResult[0]);
		
		
	}
	/**
	 * 针对SEI和SIB不在统一个包内的情况,先查找操作对应的Qname,
	 * client通过Qname调用对应操作
	 * @param client
	 * @param operation
	 * @return
	 */
	private static QName getOperateQName(Client client,String operation){
		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;  
		        }  
		    }  
		}
		log.info("Operation:"+operation+",namespaceURI:" + opName.getNamespaceURI());
		return opName;
	}
}

强烈建议使用第一种方式,符合规范。

0
1
分享到:
评论

相关推荐

    CXF动态webservice客户端demo

    使用CXF生成动态调用webservice接口的客户端,也比较简单。

    2009 达内Unix学习笔记

    集合了 所有的 Unix命令大全 ...telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss ... 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ ... 命令和参数之间必需用空格隔...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: After deleting the selected points in the TFlexPanel.DeleteSelectedPoints the all figures with one point also deleted. - FIX: When the curve contain more then one figure and they were all ...

    acpi控制笔记本风扇转速

    control method attempts to create 2 objects of the same name. This once again returns AE_ALREADY_EXISTS. When this exception occurs, it invokes the mechanism that will dynamically serialize the ...

    微软内部资料-SQL性能优化3

    There was no way to prevent non-repeatable reads while not preventing phantoms. By default, SQL Server 2000 operates at an isolation level of READ COMMITTED. To make use of either more or less strict...

    VclZip pro v3.10.1

    This was due to a problem where it would be freed automatically if there was a problem with the ArchiveStream when trying to open it as a zip file (possibly corrupt). Best practice is that ...

    Java邮件开发Fundamentals of the JavaMail API

    included with the 1.2.1 version of the Java 2 Platform, Enterprise Edition (J2EE), so it is still commonly used. The version of the JavaMail API you want to use affects what you download and install...

    微软内部资料-SQL性能优化5

    A clustered index is like a telephone directory in which all of the rows for customers with the same last name are clustered together in the same part of the book. Just as the organization of a ...

    NewSID(光学习一下代码就可以了,没看清楚介绍别运行)

    When the SID is found in a value it is replaced with the new computer SID, and when the SID is found in a name, the key and its subkeys are copied to a new subkey that has the same name except with ...

    曲线拟合工具CurveExpert 1.0

    + Entering a user model with no parameters was allowed when it shouldn't have been. Now, a syntax error is generated. + the Window|Tile command sometimes worked strangely if graphing windows had ...

    servlet2.4doc

    Returns the object bound with the specified name in this session, or null if no object is bound under the name. getAttributeNames() - Method in interface javax.servlet.ServletContext Returns an ...

    BURNINTEST--硬件检测工具

    - Minor changes to the No operation error watchdog timer for the CD and Hard disk tests. - Minor correction to the Butterfly seek test. - Video playback trace logging increased. Release 5.3 build ...

    Sakemail

    A obscure bug was found by HuangYeJun from china, in the RetrieveHeaders function if the retrieved text was larger than 1024 bytes and the crlf.crlf fall in the middle of two chunks, the function is ...

    Bochs - The cross platform IA-32 (x86) emulator

    Now the USB device classes no longer exist twice if both HC plugins are loaded. - added 'pseudo device' in common USB code for the device creation. This makes the HCs independent from the device ...

    BlueToolInstall

    1.3. “Broadcom Product” means any of the proprietary integrated circuit product(s) sold by Broadcom with which the Software was designed to be used, or their successors. 1.4. “Derivative Work” ...

    Senfore_DragDrop_v4.1

    * The name and exact version of your operating system (e.g. NT4 SP5). * The exact version of the Internet Explorer installed on your system. If you can provide me with a minimal application which ...

    Delphi7.1 Update

    * Using the Delphi 7 version of midas.dll to open an XML file that was saved with the Delphi 6 version of midas.dll results in an illegal operation. * Incorrect filter expression parsing occurs when ...

    LCTF软件备份VariSpec™ Liquid Crystal Tunable Filters

    This was not handled properly, so if a call was made to VsOpen when no VariSpec was present, but a later call was made when a filter was present, the latter would fail. b) VsGui added check of which...

    二级减速器课程设计说明书reducer design specification.doc

    (1) we have cultivated the design idea of combining theory with practice, trained our ability to comprehensively apply the basic theory of mechanical design course and other related courses, analyze ...

    端口查看工具

    name, full path of the process, version information of the process (product name, file description, and so on), the time that the process was created, and the user that created it. In addition, ...

Global site tag (gtag.js) - Google Analytics