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;
	}
}


你可能感兴趣的:(android,android,android,webservice,webservice,SOAP,SOAP,3.0)