WebService

来源:互联网 发布:百鸟朝凤 知乎 编辑:程序博客网 时间:2024/06/03 17:41

采用的免费webservice接口:

http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl

客户端代码如下:

package com.web.hh.constroller;import javax.xml.namespace.QName;import org.apache.axis2.AxisFault;import org.apache.axis2.addressing.EndpointReference;import org.apache.axis2.client.Options;import org.apache.axis2.rpc.client.RPCServiceClient;import org.apache.axis2.transport.http.HTTPConstants;public class ClientWeatherRPC {    /*     * 第三种方式,RPC     */    public static void main(String[] args) throws AxisFault {        //使用RPC方式调用WebService                 RPCServiceClient serviceClient = new RPCServiceClient();            Options options = serviceClient.getOptions();    //        options.setExceptionToBeThrownOnSOAPFault(false);          options.setSoapVersionURI(org.apache.axiom.soap.SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);         options.setProperty(HTTPConstants.CHUNKED, "false");        //指定调用WebService的URL            EndpointReference targetEPR = new EndpointReference("http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl");            options.setTo(targetEPR);            options.setAction("http://WebXml.com.cn/getWeather");          //指定方法的参数值            Object[] opAddEntryArgs = new Object[] {"昌平",""};            //指定要调用的方法及WSDL文件的命名空间            QName opAddEntry = new QName("http://WebXml.com.cn/", "getWeather");            //调用法并输出该方法的返回值    //        System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs));          Object[] result=serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, new Class[]{String.class});         for (Object object : result) {             System.out.println(object.toString());         }     }}

运行抛异常:

十一月 02, 2017 2:04:58 下午 org.apache.axis2.deployment.ModuleDeployer deploy信息: Deploying module: addressing-1.6.2 - file:/F:/soft-install-soft/MavenRep/org/apache/axis2/axis2/1.6.2/axis2-1.6.2.jarException in thread "main" org.apache.axis2.AxisFault: 服务器无法处理请求。 ---> 值不能为空。参数名: input    at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)    at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)    at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)    at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:555)    at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:531)    at org.apache.axis2.rpc.client.RPCServiceClient.invokeBlocking(RPCServiceClient.java:102)    at com.web.hh.constroller.ClientWeatherRPC.main(ClientWeatherRPC.java:34)

这里写图片描述

在网上找了许多资料,都没有得到解答。如有知晓的,多多指教,不胜感激!!!

原创粉丝点击