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

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

分类: WebService 1893人阅读 评论(0) 收藏 举报

 package axiom;

import java.util.Date;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties;

public class WeatherAxiomClient {

 private static EndpointReference targetEPR =
        new EndpointReference(
                              "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");
 
 private static OMFactory fac = OMAbstractFactory.getOMFactory();
 static OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/", "tns");
 
 public static void main(String args[]) throws AxisFault{
  Date start=new Date();
        System.out.println("start:"+start);
        ServiceClient sender = new ServiceClient();
       
        /****************************City**************************************/
        //sender.setOptions(buildOptions("http://WebXml.com.cn/getSupportCity"));
        //OMElement result = sender.sendReceive(buildParam("getSupportCity",new String[]{"byProvinceName"},new String[]{"All"}));
        //查询本天气预报Web Services支持的国内外城市或地区信息
        /**************************************************************************/
       
        /****************************Province**************************************/
        //sender.setOptions(buildOptions("http://WebXml.com.cn/getSupportProvince"));
        //OMElement result = sender.sendReceive(null);
        //调用得到province方法,获得本天气预报Web Services支持的洲、国内外省份和城市信息
        /**************************************************************************/
       
        /****************************DataSet**************************************/
        //sender.setOptions(buildOptions("http://WebXml.com.cn/getSupportDataSet"));
        //OMElement result = sender.sendReceive(null);
        //获得本天气预报Web Services支持的洲、国内外省份和城市信息
        /**************************************************************************/
       
       
        /****************************Weather**************************************/
        //sender.setOptions(buildOptions("http://WebXml.com.cn/getWeatherbyCityName"));
        //OMElement result = sender.sendReceive(buildParam("getWeatherbyCityName",new String[]{"theCityName"},new String[]{"杭州"}));
        //根据城市或地区名称查询获得未来三天内天气情况、现在的天气实况、天气和生活指数
        /**************************************************************************/
       
       
       
        sender.setOptions(buildOptions("http://WebXml.com.cn/getWeatherbyCityNamePro"));
        OMElement result = sender.sendReceive(buildParam("getWeatherbyCityNamePro",new String[]{"theCityName","theUserID"},new String[]{"杭州","01"}));
       
        System.out.println(result);
        Date end=new Date();
        System.out.println("end:"+end);
        System.out.println("between:"+(end.getTime()-start.getTime()));
 }
 /**
  * @see 调用webservice得到天气预报支持的城市
  * @return
  */
 public static  OMElement buildParam(String method,String[] arg,String[] val) {
        OMElement data = fac.createOMElement(method, omNs);
        for(int i=0;i<arg.length;i++){
        OMElement inner = fac.createOMElement(arg[i], omNs);
        inner.setText(val[i]);
        data.addChild(inner);
        }
        return data;

 }
 

 /**
  * @see 设置连接属性
  * @return
  */
 public static Options  buildOptions(String action){
  Options options = new Options();
        options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
        options.setAction("http://WebXml.com.cn/getSupportCity");
        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);
        //options.setAction(action);
        return options;

 }
 
 /**
  * @see 设置代理属性
  * @return
  */
 public static ProxyProperties buildProxy(){
     ProxyProperties proxyProperties=new ProxyProperties();
        proxyProperties.setProxyName("172.19.18.22");
        proxyProperties.setProxyPort(8080);
        return proxyProperties;
 }
 
 
}
问题出在我注释的确一行.一定要设置Action.否则服务器无法处理请求,不知道你引用的是哪个方法,所以报出未将对象引用设置到对象的实例



转载地址:  http://blog.csdn.net/a1000005a/article/details/4770052

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
org.apache.axis.axisfault: (400)400是一种错误的异常类型,通常在Apache Axis框架中出现。这个异常表示客户端发送的请求出现了错误,并且服务器无法处理这个请求。具体的错误信息可能因情况而异。 这个异常是由HTTP状态码400引起的,即"Bad Request"。它意味着客户端发送的请求数据存在问题,服务器无法理解或处理。可能的原因包括请求的格式错误、缺少必需的参数、参数值不正确等。 要解决这个异常,我们需要检查请求的内容和参数是否正确,并与服务器的要求相匹配。可以尝试以下解决方法: 1. 检查请求的格式:确保请求的格式符合服务器所需的标准格式。 2. 检查参数是否正确:验证请求中的参数是否正确,并且值符合服务器的要求。 3. 检查参数是否完整:确保请求中包含了服务器所要求的所有参数,没有遗漏。 4. 检查权限和凭证:有些API可能需要身份验证或授权,确保在请求中包含了正确的凭证。 5. 检查网络连接:有时候,错误是由网络连接问题引起的。确保网络连接稳定,并且客户端与服务器之间的通信没有问题。 如果以上方法都没有解决问题,那么可能需要进一步查看服务器的错误日志以获取更具体的错误信息。最重要的是,根据服务器的文档和要求,确保请求的内容与服务器的要求相匹配,并遵循正确的API调用流程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值