android_天气预报

来源:互联网 发布:女生鞋子淘宝网 编辑:程序博客网 时间:2024/05/05 06:08

原址:http://blog.sina.com.cn/s/blog_778ad61301019fyb.html

 

package com.easytalent.android.meizu;

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

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class MainActivity1 extends Activity{
 
 private TextView text_view = null;
 private static final String serviceNameSpace = "http://WebXml.com.cn/";//此处必须有最后一个反斜杠
 private static final String method = "getSupportCityDataset";
 private static final String url= "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx";//这个地址要正确
 private static final String SOAP_ACTION = "http://WebXml.com.cn/getSupportCityDataset";
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_front);
//  Intent intent = getIntent();
//  String value = intent.getStringExtra("testName");
  
  //获得返回的list数据
  Log.d("tag", getRequestData());
  String cityName = this.getRequestData();
  
  text_view = (TextView)findViewById(R.id.text_view);
  text_view.setText(cityName);
  }
 
 public String getRequestData(){
  try{
   
   SoapObject request = new SoapObject(serviceNameSpace,method);
   request.addProperty("theRegionCode","上海");//参数
   SoapSerializationEnvelope envelop;//序列化envelope
   envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
   envelop.dotNet = true;
   envelop.setOutputSoapObject(request);
   envelop.bodyOut = request;
   envelop.encodingStyle = "UTF-8";
   
   HttpTransportSE httpClient = new HttpTransportSE(url);
   httpClient.debug = true;
   
   httpClient.call(SOAP_ACTION,envelop);
   
   if(envelop.getResponse() != null){
    SoapObject result = (SoapObject)envelop.getResponse();
    return envelop.bodyIn.toString();
   }
   return null;
   
  }catch(Exception e){
   e.printStackTrace();
  }
  return null;
 }
 
 

}

0 0
原创粉丝点击