把自己坑的Could not invoke service..
来源:互联网 发布:大数据用什么数据库 编辑:程序博客网 时间:2024/06/16 16:53
最近第一次使用xfire写了一个Webservice类,之前在项目上已经有了其他webservice方法,由于需要自己又写了一个方法,用IDE的Web Service Client自动生成了客户端代码,然后就把自己坑死了。。。。用来记录自己傻代码,半天劲找到原因,也是醉了,只是为了给自己警醒,以后规范代码,没什么特殊情况方法名首字母小写,谢谢~~~。
具体错误:
org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Invalid operation: {http://com.service}upTest
org.codehaus.xfire.fault.XFireFault: Invalid operation: {http://com.service}upTest
at org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)
at org.codehaus.xfire.fault.SoapFaultSerializer.readMessage(SoapFaultSerializer.java:28)
at org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:111)
at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Client.onReceive(Client.java:406)
at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
at org.codehaus.xfire.client.Client.invoke(Client.java:336)
at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
at sun.proxy.$Proxy0.upTest(Unknown Source)
at com.test.WsClient.main(WsClient.java:67)
原因:无法invoke方法upTest
其实从字面意思就是无法生成upTest方法
具体原因:由于在服务端方法名为UpTest方法,在经过Web Service Client 根据wsdl地址生成的客户端代码,自动将UpTest规范为upTest,于是在调用的时候就成了upTest方法了,然后两边就不匹配了(蛋疼的客户端,这么规范)。我以为自动生成了这样的结构,会根据什么匹配规则自己对应呢,结果它只是给我规范了方法名,就不管了。
测试例子如下:
使用的Xfire,服务端引入相应的jar,然后配置web.xml中的servlet,然后在servis.xml配置发布的接口
web.xml,services.xml的就不贴了
具体接口如下:
package com.service;
/**
* test
*/
public interface ITestService {
/**
* 标准小写格式
*/
public String lowTest(String test,String test1);
/**
* 不标准的大写格式
*/
public String UpTest(String sPdf,String filename);
}
然后实现类:
package com.service.impl;
import com.service.ITestService;
/**
*/
public class TestServiceImpl implements ITestService {
@Override
public String lowTest(String sPdf, String filename) {
System.out.println("这是标准格式");
return "lower";
}
@Override
public String UpTest(String sPdf, String filename) {
System.out.println("设置大写开头的方法");
return "upper";
}
}
这里有两个方法,一个是标准格式的,即首字母小写的方法,一个不是不标准的,即首字母大写的方法。
服务端架构如下:
启动server端,可以访问wsdl地址,然后继续启动不要停
接下新建一个客户端项目,然后使用IDE的Web Service Client ,next ,输入wsdl地址,完成
然后就会自动生成客户端代码
这里注意了:
然后新建main方法测试:
代码如下:
Service ws1 = new ObjectServiceFactory().create(TestPortType.class);
//创建代理工厂
XFireProxyFactory factory1 = new XFireProxyFactory(XFireFactory.newInstance().getXFire());//创建工厂实例
String helloURL1 = "http://localhost:8080/WsServer/services/test";
try {
TestPortType ser1 = (TestPortType) factory1.create(ws1, helloURL1);
String t1 = ser1.lowTest("", "");
System.out.println(t1);
String t2 = ser1.upTest("", "");
System.out.println(t2);
} catch (Exception e) {
e.printStackTrace();
}
输出结果:
lower
org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Invalid operation: {http://com.service}upTest
org.codehaus.xfire.fault.XFireFault: Invalid operation: {http://com.service}upTest
......
即lowTest方法正常执行了,但是upTest方法报错。就是因为在server端是UpTest,经过客户端自动生成的代码变成了upTest.........
- 把自己坑的Could not invoke service..
- The AXIS engine could not find a target service to invoke! targetService is ccengine
- org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehau
- org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Server returned error code = 40
- org.apache.axis2.AxisFault: The AXIS engine could not find a target service to invoke! targetServic
- xfire客户端调用服务端报错 XFireRuntimeException: Could not invoke service.. Server returned error code = 4ji
- “Service 'Driver' could not bind on port”错误的解决方法
- could not start the service mysql
- MySQL安装,could not start the service
- MySql could not start the service
- Could not start the service MySQL 解决方法
- MySql The service could not be started
- webservice: Could not initialize Service NoSuchMethodException getPortClassMap()
- webservice: Could not initialize Service NoSuchMethodException getPortClassMap()
- Could not resolve hostname 。。。。。。: Name or service not known
- Oracle ORA-12154: TNS:could not resolve service name错误的解决方法
- ORA-12154: TNS:could not resolve service name无法解析指定的连接标志符
- Oracle ORA-12154: TNS:could not resolve service name错误的解决方法
- Java
- 栈 洛谷p1044
- 调整Hyperion Planning 作业控制台日志保留期限
- java常用类库---正则表达式
- Vue.js开发环境搭建的介绍
- 把自己坑的Could not invoke service..
- 数据中心标准旨在实现OCP未能实现的功能
- mysql计算两个日期之间的时间差
- 2017第十六届浙江(杭州)装备制造业博览会会刊(参展商名录)
- 其他题目---从N个数中等概率打印M个数
- okHttp封装
- iptables实现网络防火墙(一)
- 图解phpstorm常用快捷键
- JavaThink读书笔记