axis2调用webservice接口,org.apache.axis2.AxisFault: 服务器无法处理请求。 ---> 未将对象引用设置到对象的实例。

gw574813284 2012-05-17 10:38:30



package com.axis;
import javax.xml.namespace.QName;

import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;

public class Test {


private static final String wsdl = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";
private static final String namespace="http://WebXml.com.cn";

public static String[] testWeather(String theCityName){
String[] result=null;


try {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(wsdl);
options.setAction(namespace+"/getWeatherbyCityName");
options.setTo(targetEPR);
//options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
// options.setProperty(HTTPConstants.CHUNKED, "false");//设置不受限制.
// options.setProperty(HTTPConstants.PROXY, buildProxy());
// options.setProperty(Constants.Configuration.HTTP_METHOD,HTTPConstants.HTTP_METHOD_POST);

Object[] arg = new Object[]{theCityName}; // 复杂参数
Class[] classes = new Class[]{String.class};
QName opName = new QName(namespace,"getWeatherbyCityName");
result = (String[])serviceClient.invokeBlocking(opName,arg,classes)[0];
if (result != null){
return result;
}
} catch (Exception e) {
e.printStackTrace();
}

return result;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
String[] weather = testWeather("58367");
for(String w : weather){
System.out.println(w);
}
}



}







这是源码。
jar包:
activation-1.1.jar
annogen-0.1.0.jar
aspire-secr-adc.jar
axiom-api-1.2.5
axiom-impl-1.2.5.jar
axis2-1.3.jar
commons-codec-1.3.jar
commons-httpclient-3.1.jar
commons-logging-1.1.jar
stax-api-1.0.1(FOR JDK1.5).jar
wsdl4j-1.6.2.jar
wstx-asl-3.2.1.jar
XmlSchema-1.3.2.jar

错误信息:

log4j:WARN No appenders could be found for logger (org.apache.axis2.util.Loader).
log4j:WARN Please initialize the log4j system properly.
org.apache.axis2.AxisFault: 服务器无法处理请求。 ---> 未将对象引用设置到对象的实例。
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:486)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:343)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:389)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:211)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:528)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:508)
at org.apache.axis2.rpc.client.RPCServiceClient.invokeBlocking(RPCServiceClient.java:101)
at com.axis.Test.testWeather(Test.java:35)
at com.axis.Test.main(Test.java:50)
Exception in thread "Main Thread" java.lang.NullPointerException
at com.axis.Test.main(Test.java:51)


环境为:jdk1.5+weblogic9.2.3

本人刚刚接触webservice。

谢谢大家了。



...全文
1928 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
溪风编程 2013-04-03
  • 打赏
  • 举报
回复
楼主你的问题解决了吗?我也是这个问题,请求支援
WarOfTheKing 2012-09-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

怎么喜欢用这种风格来调用呢?我一直都很少这么调用
[/Quote]
请问你是怎么调用的?
varyall 2012-09-14
  • 打赏
  • 举报
回复
不过我们那个时候的是客户端是生成存根STUB那种形式的
varyall 2012-09-14
  • 打赏
  • 举报
回复
你这个webservice 应该是.net发布的吧,java调用.net
// options.setProperty(HTTPConstants.CHUNKED, "false");//设置不受限制.
这个最好设置好了,我们之前做项目,用java调用.net,那个时候不设置这个就出错呢
varyall 2012-09-14
  • 打赏
  • 举报
回复
怎么喜欢用这种风格来调用呢?我一直都很少这么调用
WarOfTheKing 2012-09-14
  • 打赏
  • 举报
回复
我今天也和你一样出了这个错误,求解啊!

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧