1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > @webservice报错org.apache.cxf.common.i18n.UncheckedException: No operation was found with

@webservice报错org.apache.cxf.common.i18n.UncheckedException: No operation was found with

时间:2023-08-16 03:36:22

相关推荐

@webservice报错org.apache.cxf.common.i18n.UncheckedException: No operation was found with

文章目录

1. 现象2. 解决办法13. 解决办法2
1. 现象

整合spring+cxf的webservice,成功发布了wsdl,但在调用的时候报错

org.mon.i18n.UncheckedException: No operation was found with;

2. 解决办法1

: 在service接口中添加targetNamespace

package com.gblfy.service;import javax.jws.WebMethod;import javax.jws.WebParam;import javax.jws.WebService;@WebService(targetNamespace = "http://impl./")public interface IUserService {@WebMethodpublic String getCxf(@WebParam(name = "reqXml") String reqXml);}

实现类

package com.gblfy.service.impl;import com.gblfy.service.IUserService;import javax.jws.WebService;@WebServicepublic class UserServiceImpl implements IUserService {@Overridepublic String getCxf(String reqXml) {System.out.println("接收到的报文:" + reqXml);return "OK";}}

客户端

/*** 单/多参调用工具类(Object类型)** @param cxfUrl url地址* @param method 调用方法名* @param reqXml 发送报文体* @return res 返回结果* @throws Exception 若有异常,在控制台输出异常,并将异常抛出*/public static String cxfClientParam(String cxfUrl, String method, Object... reqXml) throws Exception {String res = null;// 创建动态客户端JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();Client client = dcf.createClient(cxfUrl);// 需要密码的情况需要加上用户名和密码// client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME, PASS_WORD));Object[] objects = new Object[0];try {// 基本格式:invoke("方法名",参数1,参数2,参数3....);objects = client.invoke(method, reqXml);res = objects[0].toString();System.out.println("返回数据:" + res);} catch (java.lang.Exception e) {e.printStackTrace();throw e;}return res;}

3. 解决办法2

使用 QName 然后添加 service接口的地址

package com.gblfy.service.client;import org.apache.cxf.endpoint.Client;import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;import org.ponent;import javax.xml.namespace.QName;/*** cxf客户端调用(企业内部已封装)** @author gblfy* @date -09-17*/@Componentpublic class CxfClient {public static void main(String[] args) throws Exception {String cxfUrl = "http://127.0.0.1:8080/spring_cxf_war/webservice/userWS?wsdl";String method = "getCxf";String reqXml = "cxf请求报文";//调用服务CxfClient.cxfClientParam(cxfUrl, method, reqXml);}/*** 单/多参调用工具类(Object类型)** @param cxfUrl url地址* @param method 调用方法名* @param reqXml 发送报文体* @return res 返回结果* @throws Exception 若有异常,在控制台输出异常,并将异常抛出*/public static String cxfClientParam(String cxfUrl, String method, String reqXml) throws Exception {String res = null;// 创建动态客户端JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();Client client = dcf.createClient(cxfUrl);// 需要密码的情况需要加上用户名和密码// client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME, PASS_WORD));Object[] objects = new Object[0];try {// 基本格式:invoke("方法名",参数1,参数2,参数3....);QName qName = new QName("http://impl./",method);objects = client.invoke(qName, reqXml);res = objects[0].toString();System.out.println("返回数据:" + res);} catch (Exception e) {e.printStackTrace();throw e;}return res;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。