当前位置 : 主页 > 网页制作 > Nodejs >

WebService - Client调用(RPC)

来源:互联网 收集:自由互联 发布时间:2021-06-24
采用的免费webservice接口: http: //ws .webxml .com .cn /WebServices/WeatherWS .asmx ?wsdl 客户端代码如下: package com .web .hh .constroller ; import javax .xml .namespace .QName ; import org .apache .axis 2 .AxisFault ; imp

采用的免费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.jar
Exception 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)

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

网友评论