加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

WebService - Client调用(RPC)

发布时间:2020-12-16 21:42:21 所属栏目:安全 来源:网络整理
导读:采用的免费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 ; import org .apache

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

这里写图片描述

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读