package com.chaoran.thread;

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

import com.sys.SysData;
import com.util.IoUtil;

import android.os.Handler;
import android.os.Message;

public class DownDJRun implements Runnable {
    private String formlx;
    private Handler handler;
    public DownDJRun(String formlx,Handler handler){
    	this.formlx=formlx;
    	this.handler=handler;
    }
	@Override
	public void run() {
		Object ob;
		try {
			ob = getWeather(formlx);
			Message message = new Message();
			message.obj = ob;
			handler.sendMessage(message);
		} catch (Exception e) {
			Message message = new Message();
			message.obj = e.toString();
			message.what = -1;
			handler.sendMessage(message);
		}
	}
	public Object getWeather(String FORMlx) throws Exception {
		String url = SysData.url + "/webservice/ServiceInterface?wsdl";
		String method = "querydjNrWs";
		SoapObject rpc = new SoapObject("", method);
		rpc.addProperty("FORMlx", FORMlx);
		rpc.addProperty("mac", SysData.clientid);
		rpc.addProperty("userid", SysData.userid);
		HttpTransportSE ht = new HttpTransportSE(url,SysData.timeout);
		ht.debug = true;
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		ht.call("", envelope);
		Object djInitMap = null;
		if (envelope.getResponse() != null) {// 判断是否返回结果，因为我这个是一个查询操作，是带有返回值的。
			byte[] bb = org.kobjects.base64.Base64.decode(envelope
					.getResponse().toString());
			djInitMap = IoUtil.byte_obj(bb);
		}
		return djInitMap;
	}

}
