WebService
来源:互联网 发布:网页编程用什么语言 编辑:程序博客网 时间:2024/06/02 06:39
package com.example.tianqi;
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 MainActivity extends Activity {
// 名称空间
private static final String namespace = "http://www.36wu.com/";
// 方法名
private static final String name = "GetWeather";
// 请求的地址
private static final String url = "http://web.36wu.com/WeatherService.asmx?WSDL";
// action获取天气调用的地址
private static final String soapAction = "http://www.36wu.com/GetWeather";
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.tv);
// 建立方法,在线程里面写
new Thread() {
public void run() {
setWeather();
};
}.start();
}
protected void setWeather() {
SoapObject sb = new SoapObject(namespace, name);
sb.addProperty("district", "邯郸");
sb.addProperty("authkey", "5e431e2f00544a73b048b00458fb187d");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
// 输出写出来
envelope.bodyOut = sb;
envelope.dotNet = true;
// 访问网络
HttpTransportSE SE = new HttpTransportSE(url);
try {
SE.call(soapAction, envelope);
final SoapObject bodyIn = (SoapObject) envelope.bodyIn;
runOnUiThread(new Runnable() {
@Override
public void run() {
textView.setText(bodyIn.toString());
}
});
} catch (Exception e) {
e.printStackTrace();
Log.e("", e != null ? e.getMessage() : "出错了");
}
}
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 MainActivity extends Activity {
// 名称空间
private static final String namespace = "http://www.36wu.com/";
// 方法名
private static final String name = "GetWeather";
// 请求的地址
private static final String url = "http://web.36wu.com/WeatherService.asmx?WSDL";
// action获取天气调用的地址
private static final String soapAction = "http://www.36wu.com/GetWeather";
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.tv);
// 建立方法,在线程里面写
new Thread() {
public void run() {
setWeather();
};
}.start();
}
protected void setWeather() {
SoapObject sb = new SoapObject(namespace, name);
sb.addProperty("district", "邯郸");
sb.addProperty("authkey", "5e431e2f00544a73b048b00458fb187d");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
// 输出写出来
envelope.bodyOut = sb;
envelope.dotNet = true;
// 访问网络
HttpTransportSE SE = new HttpTransportSE(url);
try {
SE.call(soapAction, envelope);
final SoapObject bodyIn = (SoapObject) envelope.bodyIn;
runOnUiThread(new Runnable() {
@Override
public void run() {
textView.setText(bodyIn.toString());
}
});
} catch (Exception e) {
e.printStackTrace();
Log.e("", e != null ? e.getMessage() : "出错了");
}
}
}
1 0
- WebService
- WebService
- webservice
- webservice
- WebService
- webservice
- webService
- WebService
- WebService
- webService
- WEBService
- webService
- WebService
- [WebService]
- webservice
- WebService
- webservice
- WebService
- 硬币问题
- 浏览器开发人员工具使用初步图解
- 贪心算法-会场安排
- MFC-combox和listbox、radio button、group box等控件及onTimer函数的应用
- linux panic分析
- WebService
- Zabbix 安装部署
- 矩阵游戏(二分图匹配)
- dnw在linux下的安装方法
- GCD学习 - swift GCD使用指南
- excel-vba组内离均差
- Cadence基础知识1(CADENCE从原理图到PCB步骤 )
- 无法嵌入互操作类型“Dongle.DongleClass”。请改用适用的接口。
- dnw在linux下的安装方法