webservice android

Webservice,服务器与客户端通信通过相互发送XML文件,首先是客户端向服务器发送XML文件,

服务器解析命令后返回相应操作,基于POST协议。在Android中也有相应轻量级的SOAP包,现在已经更新

到3.0版本,之前自己写了一个,最后落在XML解析,决定还是使用现成包来开发项目。具体使用方法:

package com.hygame.soap;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class FamobileSoap {

	public static String getRemoteInfo(String Pin_card, String serial_card) {
		// 命名空间
		String nameSpace = "http://tempuri.org/";
		// 调用的方法名称
		String methodName = "Galaxy_PaymentCard";
		// EndPoint
		String endPoint = "http://eway.mgates.vn/galaxycard/ws.asmx";
		// SOAP Action
		String soapAction = "http://tempuri.org/Galaxy_PaymentCard";

		// 指定WebService的命名空间和调用的方法名
		SoapObject rpc = new SoapObject(nameSpace, methodName);

		// <fa_account>string</fa_account>
		// <Pin_card>string</Pin_card>
		// <Serial_card>string</Serial_card>
		// <Card_type>string</Card_type>
		// <Username>string</Username>
		// <Signature>string</Signature>
		// <ChannelID>string</ChannelID>

		rpc.addProperty("fa_account", "famobile_galaxy");
		rpc.addProperty("Pin_card", "123456789012");
		rpc.addProperty("serial_card", "12345678900123456789");
		rpc.addProperty("type_card", "VMS");
		rpc.addProperty("UserName", "bingo");
		rpc.addProperty("Signature", FamobilePay
				.MD5("famobile_galaxy12345678901212345678900123456789VMSbingo"));
		rpc.addProperty("ChannelID", "0");

		// 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER10);

		envelope.bodyOut = rpc;
		// 设置是否调用的是dotNet开发的WebService
		envelope.dotNet = true;
		// 等价于envelope.bodyOut = rpc;
		envelope.setOutputSoapObject(rpc);

		HttpTransportSE transport = new HttpTransportSE(endPoint);
		try {
			// 调用WebService
			transport.call(soapAction, envelope);
		} catch (Exception e) {
			e.printStackTrace();
		}

		// 获取返回的数据
		SoapObject object = (SoapObject) envelope.bodyIn;
		String result = object.getProperty(0).toString();
		System.out.println(result);
		return result;
	}
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值