android调用webservice

本文详细介绍了如何利用KSOAP2库在Android应用中调用远程Web Service,包括设置SOAPAction、定义命名空间和方法、构造SOAP请求及响应解析等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先导入 ksoap2-android-assembly-2.4-jar-with-dependencies.jar

 public static String queryRemoteInfor(String params) throws Exception{
		    String result = "";
	            String soapAction = "http://命名空间"+"调用方法名";// SOAP Action
                    SoapObject rpc = new SoapObject("http://命名空间", "调用方法名");// 指定WebService的命名空间和调用的方法名
		    // 设置需调用WebService接口需要传入的参数
		    rpc.addProperty("param", params);
		    
		    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
		        SoapEnvelope.VER10);// 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本
		    envelope.bodyOut = rpc;
		    envelope.setOutputSoapObject(rpc);
		    HttpTransportSE transport = new HttpTransportSE("http://xxxxx/cyservice/services/cyservice");//webservice如果是xife写的,就不要wsdl后缀
		  //  HttpTransportSE transport = SingletonHttpTransportSe.getInstance();
		    try {
		      transport.call(soapAction, envelope);
		      // 获取返回的数据  
		      Object response = envelope.getResponse();
		      result = String.valueOf(response);
		      if (null == result ||result.equals("anyType{}") || result.equals("[]")) {
		        result="";
		      }
		      Log.i("webserviceeeeeeeee","成功");
		          return result;
		    } catch (Exception e) {
		      e.printStackTrace();
		      Log.i("webserviceeeeeeeee","失败");
		      throw new Exception();
		    }
		  }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值