package com.bwie.day_webservice___;
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.transport.HttpsTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity {
static final String name = "GetWeather";
static final String namespace = "http://www.36wu.com/";
// 设置访问的url地址
static final String URL = "http://web.36wu.com/WeatherService.asmx?WSDL";// 大小写转换快捷键:shift+ctrl+x/:shift+ctrl+y
static final String SOAPAction = "http://www.36wu.com/GetWeather";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 开启子线程做联网操作
new Thread() {
public void run() {
getInfo();
};
}.start();
}
/**
* 联网获得天气情况
*/
private void getInfo() {
// 設置命名空間,及访问的方法名
SoapObject soapObject = new SoapObject(namespace, name);
// 携带要查询的数据
soapObject.addProperty("district", "石家庄");
soapObject.addProperty("authkey", "550ca5eabce54de7a4cc40ce49929311");
// 得到HttpTransportSE对象,设置访问url
HttpTransportSE se = new HttpTransportSE(URL);
// 得到serializationEnvelope對象,设置Soap版本号
SoapSerializationEnvelope serializationEnvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
// 设置发送给服务器的信息
serializationEnvelope.bodyOut = soapObject;
// 设置支付.NET语言
serializationEnvelope.dotNet = true;
try {
// 发送请求
se.call(SOAPAction, serializationEnvelope);
// 得到服务器返回的数据
SoapObject soapObject_in = (SoapObject) serializationEnvelope.bodyIn;
System.out.println("============"+soapObject_in.toString());
//得到GetWeatherResult字段下包含的信息
SoapObject getWeatherResult=(SoapObject) soapObject_in.getProperty("GetWeatherResult");
System.out.println(getWeatherResult.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.transport.HttpsTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity {
static final String name = "GetWeather";
static final String namespace = "http://www.36wu.com/";
// 设置访问的url地址
static final String URL = "http://web.36wu.com/WeatherService.asmx?WSDL";// 大小写转换快捷键:shift+ctrl+x/:shift+ctrl+y
static final String SOAPAction = "http://www.36wu.com/GetWeather";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 开启子线程做联网操作
new Thread() {
public void run() {
getInfo();
};
}.start();
}
/**
* 联网获得天气情况
*/
private void getInfo() {
// 設置命名空間,及访问的方法名
SoapObject soapObject = new SoapObject(namespace, name);
// 携带要查询的数据
soapObject.addProperty("district", "石家庄");
soapObject.addProperty("authkey", "550ca5eabce54de7a4cc40ce49929311");
// 得到HttpTransportSE对象,设置访问url
HttpTransportSE se = new HttpTransportSE(URL);
// 得到serializationEnvelope對象,设置Soap版本号
SoapSerializationEnvelope serializationEnvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
// 设置发送给服务器的信息
serializationEnvelope.bodyOut = soapObject;
// 设置支付.NET语言
serializationEnvelope.dotNet = true;
try {
// 发送请求
se.call(SOAPAction, serializationEnvelope);
// 得到服务器返回的数据
SoapObject soapObject_in = (SoapObject) serializationEnvelope.bodyIn;
System.out.println("============"+soapObject_in.toString());
//得到GetWeatherResult字段下包含的信息
SoapObject getWeatherResult=(SoapObject) soapObject_in.getProperty("GetWeatherResult");
System.out.println(getWeatherResult.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}