Android开发之使用Web Service进行网络编程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Android开发之使用Web Service进行网络编程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含19255字,纯文字阅读大概需要28分钟。
内容图文
使用 Web Service 进行网络编程
Android 应用通常都是执行在手机平台上。手机系统的硬件资源是有限的,无论是存储 能力还是计算能力都有限。在 Android 系统上开发、执行一些单用户、小型应用是可能的,
但对于须要进行大量的数据处理、复杂计算的应用。还是仅仅能部署在远程server上, Android 应用将仅仅是充当这些应用的client。
为了让 Android 应用与远程server之间进行交互 ,能够借助子 Java 的 RMI 技术,但这要求远程server程序必须採用 Java 实现;也能够借助于 CORBA 技术。但这样的技术显得过于复杂,除此之外, Web Service 是一种不错的选择。
1.Web Service 平台概述
Web Service 平台主要涉及的技术有 SOAP(Simple Object Access Protocol, 简单对象訪问协议), WSDL( Web Service Description Language 。 Web Service 描写叙述语言)。 UDDI(UniversalDescription, Description and Integration ,统一描写叙述、发现和整合协议)。
1.1. SOAP (简单对象訪问协议)
SOAP (SimpleObject Access Protocol, 简单对象訪问协议)是一种具有扩展性的; XML 消息协议。 SOAP 同意一个应用程序向还有一个应用程序发送 XML 消息, SOAP 消息是从 SOAP 发送者传至 SOAP 接收者的单路消息,不论什么应用程序均可作为发送者或接收者。 SOAP 仅定义消息结构和消息处理的协议,与底层的传输协议独立。因此。 SOAP 协议能通过 HTTP, JMS 或 SMTP 协议传输。
SOAP 依赖于 XML 文档来构建,一条 SOAP 消息就是一份特定的 XML 文档, SOAP 消息包合例如以下三个主要元素:
? 必需的 <Envelope.../> 根元素。 SOAP 消息相应的 XML 文档以该元素作为根元素。
? 可选的 <Header../> 元素。包括 SOAP 消息的头信息。
? 必需的 <Body../> 元素,包括全部的调用和响应信息。
就眼下的 SOAP 消息的结构来看。 <Envelope.../> 根元素的通常仅仅能包括两个子元素,第 一 个子元素是可选的 <Header../> 元素,第二个子元素是必需的 <Body../> 元素。
1.2. WSDL ( WebService 描写叙述语言)
WSDL (WebService Description Language, Web Service 描写叙述语言 ) 使用 XML 描写叙述 Web Service 。包含訪问和使用 WebService 所必需的信息,定义该 Web Service 的位置、功能及怎样通信等描写叙述信息。
一般来说。仅仅要调用者可以获取 WebService 相应的 WSDL, 就行从中了解它所提供的服务及怎样调用 Web Service 。由于一份 WSDL 文件淸晰地定义了三个方面的内容。
? WHAT 部分:用于定义 Web Service 所提供的操作(或方法),也就是 Web Service 能做些什么。由 WSDL 中的 <types. ../> 、 <message…/> 、和 <portTyp…/> 元素定义。
? HOW 部分:用于定义怎样訪问 Web Service, 包含数据格式详情和訪问 Web Service 操作的必要协议。
也就是定义了怎样訪问Web Service。
? WHERE 部分:用于定义 Web Service 位于何处。怎样使用特定协议决定的网络地址(如 URL) 指定。该部分使用 <service.../> 元素定义。可在 WSDL 文件的最后部分看到 <service.../> 元素。
一份 WSDL 文档通常可分为两个部分:
? 第一个部分定义了服务接口,它在 WSDL 中由 <message.../> 元素和 <portType…/> 两个元素组成,当中 <message.../> 元素定义了操作的交互方式。而 <portType…/> 元素里则可包括随意数量的 <operation.../> 元素。每一个 <operation.../> 元素代表一个同意远程调用的操作(即方法)。
? WSDL 的第二个部分定义了服务实现,它在 WSDL 中由 <binding.../> 元素和 <service.../> 两个元素组成,当中 <binding.../> 定义使用特定的通信协议、数据编码模型和底层通信协议,将 Web Service 服务接口定义映射到详细实现。
而 <service.../>元素则包括一系列的<portType…/>子元素。< portType.../>子元素将会把绑定机制、服务訪问协议和端点地址结合在一起。
1.3. UDDI (统一描写叙述、发现和整合协议)
UDDI (UniversalDescription, Description and Integration, 统一描写叙述、发现和整合协议)是一套信息注冊规范,它具有例如以下特点:
? 基于 Web 。
? 分布式。
UDDI 包含一组同意企业向外注冊 WebService 、以使其它企业发现訪问的实现标准。
UDDI 的核心组件是 UDDI 注冊中心,它使用 XML 文件来描写叙述企业及其提供的 Web Service, 通过使用 UDDI, Web Service 提供者能够对外注冊 Web Service, 从而同意其它企业来调用该企业注冊的 Web Service 。 Web Service 提供者通过 UDDI 注冊中心的 Web 界面。将它所供的 Web Service 的信息增加 UDDI 注冊中心,该 Web Service 就能够被发现和调用。
Web Service 使用者也通过 UDDI 注冊中心査找、发现自己所需的服务。当 Web Service 使用者找到自己所需的服务之后。能够将自己绑定到指定的 Web Service 提供者。再依据该 Web Service 相应的 WSDL 文档来调用对方的服务。
2. 使用 Android 启用调用 Web Service
Java 本身提供了丰富的 WebService 支持,比方 Sun 公司制定的 JAX-WS 2 规范,还有 Apache 开源组织所提供的 Axis1 、 Axis2 、 CXF 等,这些技术不仅能够用于很方便地对外提供 Web Service, 也能够用于简化 Web Service 的client编程。
对于手机等小型设备而言,它们的计算资源、存储资源都十分有限。因此 Android 应用 不大可能须要对外提供 Web Service 。 Android 应用通常仅仅是充当 Web Service 的client,调用远程 Web Serice 。
Google 为 Android 平台开发 WebService client提供了 ksoap2-android 项目。但这个项目 并未直接集成在 Android 平台中,还须要开发者自行下载。
2.1 为 Android 应用添加 ksoap2-android 支持的下步骤。
1) 登录 http://code.google.eom/p/ksoap2-android/ 网站。该站网站有介绍下载 ksoap2-androi 项目的方法。
2) 下载 ksoap2-android 项目的 ksoap2-android-assembly-3.0.0-RC4.jar-with-dependencies. jar 包。
3) 将下载的 jar 包放到 android 项目的 libs 文件夹下就可以。
为 Android 项目加入了 ksoap2-android 包之后,接下来借助 ksoap2-android 项目来调用 WebService 所暴露出来的操作。
2.2 使用 ksoap2-android 调用 Web Service 操作的步驟例如以下:
1) 创建 HttpTransportSE 对象,该对象用于调用 WebService 操作。
2) 创建 SoapSerializationEnvelope 对象。
提示: 从名称来看 SoapSerializationEnvelope 代表一个 SOAP 消息封包;但 ksoap2-android 项目对 SoapSerializationEnvelope 的处理比較特殊,它是 HttpTransportSE 调用 WebService 时信息的载体。client须要传入的參数,须要通过 SoapSerializationEnvelope 对象的 bodyOut 属性传给server;server响应生成的 SOAP 消息也通过该对象的 body Out 属性来获取。
3) 创建 SoapObject 对象。创建该对象时须要传入所要调用 WebService 的命名空间、 Web Service 方法名。
4) 假设有參数须要传给 Web Service server端。调用 SoapObject 对象的 addProperty(Stringname , Object value) 方法来设置參数,该方法的 name 參数指定參数名。 value 參数指定參数值。
5) 调用 SoapSerializationEnvelope 的 setOutputSoapObject() 方法。或者直接对 bodyOut 属性赋值,将前两步创逆的 SoapObject 对象设为 SoapSerializationEnvelope 的传出 SOAP 消息体。
6) 调用对象的 call() 方法,并以 SoapSerializationEnvelope 作为參数调用远程 WebService 。
7) 调用完毕后,訪问 SoapSerializationEnvelope 对象的 bodyln 属性,该属性返回一个 SoapObject 对象。该对象就代表了 Web Service 的返回消息。解析该 SoapObject 对象,就可以 获取调用 Web Service 的返回值。
2.3 实例 : 调用 Web Service 实现天气预报
在开发天气预报的 Android 应用之前,首先须要找到一个能够对外提供天气预报的 Web Service, 通过搜索,发现 http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx 网站 能够对外提供天气预报的 WebService 。因此程序将会调用该网站的 Web Service 来实现天气 预报。
为了让应用界面更加美观,能够訪问 http://www.webxml.com.cn/images/weather.zip 下载 各种天气图标,能够使用这些天气图标来美化应用。
本程序主要须要调用例如以下三个 Web Seivice 操作:
获取省份。
依据省份获取城市。
依据城市获取天气。
为了调用上面的三个 WebService 应用程序提供例如以下工具类。
public class WebServiceUtil { // 定义Web Service的命名空间 static final String SERVICE_NS = "http://WebXml.com.cn/" ; // 定义Web Service提供服务的URL static final String SERVICE_URL = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx" ;
// 调用远程Web Service获取省份列表 public static List<String> getProvinceList() { // 调用的方法 final String methodName = "getRegionProvince" ; // 创建HttpTransportSE传输对象 final HttpTransportSE ht = new HttpTransportSE( SERVICE_URL ); ht. debug = true ; // 使用SOAP1.1协议创建Envelop对象 final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope. VER11 ); // 实例化SoapObject对象 SoapObject soapObject = new SoapObject( SERVICE_NS , methodName); envelope. bodyOut = soapObject; // 设置与.Net提供的Web Service保持较好的兼容性 envelope. dotNet = true ; FutureTask<List<String>> task = new FutureTask<List<String>>( new Callable<List<String>>() { @Override public List<String> call() throws Exception { // 调用Web Service ht.call( SERVICE_NS + methodName, envelope); if (envelope.getResponse() != null ) { // 获取server响应返回的SOAP消息 SoapObject result = (SoapObject) envelope. bodyIn ; SoapObject detail = (SoapObject) result.getProperty( methodName + "Result" ); // 解析server响应的SOAP消息。 return parseProvinceOrCity(detail); } return null ; } }); new Thread(task).start(); try { return task.get(); } catch (Exception e) { e.printStackTrace(); } return null ; }
// 依据省份获取城市列表 public static List<String> getCityListByProvince(String province) { // 调用的方法 final String methodName = "getSupportCityString" ; // 创建HttpTransportSE传输对象 final HttpTransportSE ht = new HttpTransportSE( SERVICE_URL ); ht. debug = true ; // 实例化SoapObject对象 SoapObject soapObject = new SoapObject( SERVICE_NS , methodName); // 加入一个请求參数 soapObject.addProperty( "theRegionCode" , province); // 使用SOAP1.1协议创建Envelop对象 final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope. VER11 ); envelope. bodyOut = soapObject; // 设置与.Net提供的Web Service保持较好的兼容性 envelope. dotNet = true ; FutureTask<List<String>> task = new FutureTask<List<String>>( new Callable<List<String>>() { @Override public List<String> call() throws Exception { // 调用Web Service ht.call( SERVICE_NS + methodName, envelope); if (envelope.getResponse() != null ) { // 获取server响应返回的SOAP消息 SoapObject result = (SoapObject) envelope. bodyIn ; SoapObject detail = (SoapObject) result.getProperty( methodName + "Result" ); // 解析server响应的SOAP消息。 return parseProvinceOrCity(detail); } return null ; } }); new Thread(task).start(); try { return task.get(); } catch (Exception e) { e.printStackTrace(); } return null ; }
private static List<String> parseProvinceOrCity(SoapObject detail) { ArrayList<String> result = new ArrayList<String>(); for ( int i = 0; i < detail.getPropertyCount(); i++) { // 解析出每一个省份 result.add(detail.getProperty(i).toString().split( "," )[0]); } return result; }
public static SoapObject getWeatherByCity(String cityName) { final String methodName = "getWeather" ; final HttpTransportSE ht = new HttpTransportSE( SERVICE_URL ); ht. debug = true ; nbsp; final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope. VER11 ); SoapObject soapObject = new SoapObject( SERVICE_NS , methodName); soapObject.addProperty( "theCityCode" , cityName); envelope. bodyOut = soapObject; // 设置与.Net提供的Web Service保持较好的兼容性 envelope. dotNet = true ; FutureTask<SoapObject> task = new FutureTask<SoapObject>( new Callable<SoapObject>() { @Override public SoapObject call() throws Exception { ht.call( SERVICE_NS + methodName, envelope); SoapObject result = (SoapObject) envelope. bodyIn ; SoapObject detail = (SoapObject) result.getProperty( methodName + "Result" ); return detail; } }); new Thread(task).start(); try { return task.get(); } catch (Exception e) { e.printStackTrace(); } return null ; } }
|
上面的程序调用 Web Service 的方法还是没有改变,前面两个方法——获取系统支持的省 份列表,依据省份获取城市列表——将远程 Web Service 返回的数据解析成 List<String> 后返 回。这样方便 Android 应用使用。因为第二个方法须要返回的数据量较多,所以程序直接返 回了 SoapObject 对象。
上面的程序中调用 WebService 时将 SoapSerializationEnvelope 对象的 dotNet 属性设为 true ——由于上面这个站点是通过 .NET 来对外提供 WebService 的,因此须要将 SoapSerializationEnvelope 对象的 dotNet 属性设为 true 。
有了上面的调用 WebService 的工具类之后,接下来能够在 Activity 中使用该工具类来获 取天气服务信息。
该Activity使用了两个Spinner让用户选择省份、城市,当用户选择指定城市后,系统将会载入该程序的天气信息。
该程序的界面布局代码例如以下:
<? xml version = "1.0" encoding = "utf-8" ?> < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "wrap_content" > < LinearLayout android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:orientation = "horizontal" > < TextView android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:hint = "@string/province" /> <!-- 让用户选择省份的Spinner --> < Spinner android:id = "@+id/province" android:layout_width = "wrap_content" android:layout_height = "wrap_content" /> < TextView android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:hint = "@string/city" /> <!-- 让用户选择城市的Spinner --> < Spinner android:id = "@+id/city" android:layout_width = "wrap_content" android:layout_height = "wrap_content" /> </ LinearLayout > < TextView android:id = "@+id/weatherCurrent" android:layout_width = "fill_parent" android:layout_height = "wrap_content" /> <!-- 显示今天天气的图片和文本框 --> < LinearLayout android:layout_width = "fill_parent" android:layout_height = "wrap_content" > < ImageView android:id = "@+id/todayWhIcon1" android:layout_width = "wrap_content" android:layout_height = "wrap_content" /> < ImageView android:id = "@+id/todayWhIcon2" android:layout_width = "wrap_content" android:layout_height = "wrap_content" /> < TextView android:id = "@+id/weatherToday" android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:layout_weight = "1" /> </ LinearLayout > <!-- 显示明天天气的图片和文本框 --> < LinearLayout android:layout_width = "fill_parent" android:layout_height = "wrap_content" > < ImageView android:id = "@+id/tomorrowWhIcon1" android:layout_width = "wrap_content" android:layout_height = "wrap_content" /> < ImageView android:id = "@+id/tomorrowWhIcon2" android:layout_width = "wrap_content" android:layout_height = "wrap_content" /> < TextView android:id = "@+id/weatherTomorrow" android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:layout_weight = "1" /> </ LinearLayout > <!-- 显示后天天气的图片和文本框 --> < LinearLayout android:layout_width = "fill_parent" android:layout_height = "wrap_content" > < ImageView android:id = "@+id/afterdayWhIcon1" android:layout_width = "wrap_content" android:layout_height = "wrap_content" /> < ImageView android:id = "@+id/afterdayWhIcon2" android:layout_width = "wrap_content" android:layout_height = "wrap_content" /> < TextView android:id = "@+id/weatherAfterday" android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:layout_weight = "1" /> </ LinearLayout >
</ LinearLayout >
|
当程序载入时,程序会调用WebServiceUtil的getProvinceList()方法来获取省份列表,并 使用第一个Spinner载入、显示全部省份:当用户改变选择了省份之后。程序会调用 WebServiceUtil的getCityListByProvince(Stringprovince)方法来获取该省份的所有城市:当用户改变选择城市之后,程序会调用WebServiceUtil的getWeatherByCity(StringcityName)方法 获取该城市的天气。
该Activity的代码例如以下:
public class GetWeather extends Activity { private Spinner provinceSpinner ; private Spinner citySpinner ; private ImageView todayWhIcon1 ; private ImageView todayWhIcon2 ; private TextView textWeatherToday ; private ImageView tomorrowWhIcon1 ; private ImageView tomorrowWhIcon2 ; private TextView textWeatherTomorrow ; private ImageView afterdayWhIcon1 ; private ImageView afterdayWhIcon2 ; private TextView textWeatherAfterday ; private TextView textWeatherCurrent ;
@Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout. main );
todayWhIcon1 = (ImageView) findViewById(R.id. todayWhIcon1 ); todayWhIcon2 = (ImageView) findViewById(R.id. todayWhIcon2 ); textWeatherToday = (TextView) findViewById(R.id. weatherToday ); tomorrowWhIcon1 = (ImageView) findViewById(R.id. tomorrowWhIcon1 ); tomorrowWhIcon2 = (ImageView) findViewById(R.id. tomorrowWhIcon2 ); textWeatherTomorrow = (TextView) findViewById(R.id. weatherTomorrow ); afterdayWhIcon1 = (ImageView) findViewById(R.id. afterdayWhIcon1 ); afterdayWhIcon2 = (ImageView) findViewById(R.id. afterdayWhIcon2 ); textWeatherAfterday = (TextView) findViewById(R.id. weatherAfterday ); textWeatherCurrent = (TextView) findViewById(R.id. weatherCurrent );
// 获取程序界面中选择省份、城市的Spinner组件 provinceSpinner = (Spinner) findViewById(R.id. province ); citySpinner = (Spinner) findViewById(R.id. city ); // 调用远程Web Service获取省份列表 List<String> provinces = WebServiceUtil.getProvinceList(); ListAdapter adapter = new ListAdapter( this , provinces); // 使用Spinner显示省份列表 provinceSpinner .setAdapter(adapter); // 当省份Spinner的选择项被改变时 provinceSpinner .setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> source, View parent, int position, long id) { List<String> cities = WebServiceUtil .getCityListByProvince( provinceSpinner .getSelectedItem() .toString()); ListAdapter cityAdapter = new ListAdapter(GetWeather. this , cities); // 使用Spinner显示城市列表 citySpinner .setAdapter(cityAdapter); }
@Override public void onNothingSelected(AdapterView<?> arg0) { } }); // 当城市Spinner的选择项被改变时 citySpinner .setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> source, View parent, int position, long id) { showWeather( citySpinner .getSelectedItem().toString()); }
@Override public void onNothingSelected(AdapterView<?> arg0) { } }); }
private void showWeather(String city) { String weatherToday = null ; String weatherTomorrow = null ; String weatherAfterday = null ; String weatherCurrent = null ; int iconToday[] = new int [2]; int iconTomorrow[] = new int [2]; int iconAfterday[] = new int [2]; // 获取远程Web Service返回的对象 SoapObject detail = WebServiceUtil.getWeatherByCity(city); // 获取天气实况 weatherCurrent = detail.getProperty(4).toString(); // 解析今天的天气情况 String date = detail.getProperty(7).toString(); weatherToday = " 今天:" + date.split( " " )[0]; weatherToday = weatherToday + "\n 天气:" + date.split( " " )[1]; weatherToday = weatherToday + "\n 气温:" + detail.getProperty(8).toString(); weatherToday = weatherToday + "\n 风力:" + detail.getProperty(9).toString() + "\n" ; iconToday[0] = parseIcon(detail.getProperty(10).toString()); iconToday[1] = parseIcon(detail.getProperty(11).toString()); // 解析明天的天气情况 date = detail.getProperty(12).toString(); weatherTomorrow = " 明天:" + date.split( " " )[0]; weatherTomorrow = weatherTomorrow + "\n 天气:" + date.split( " " )[1]; weatherTomorrow = weatherTomorrow + "\n 气温:" + detail.getProperty(13).toString(); weatherTomorrow = weatherTomorrow + "\n 风力:" + detail.getProperty(14).toString() + "\n" ; iconTomorrow[0] = parseIcon(detail.getProperty(15).toString()); iconTomorrow[1] = parseIcon(detail.getProperty(16).toString()); // 解析后天的天气情况 date = detail.getProperty(17).toString(); weatherAfterday = " 后天:" + date.split( " " )[0]; weatherAfterday = weatherAfterday + "\n 天气:" + date.split( " " )[1]; weatherAfterday = weatherAfterday + "\n 气温:" + detail.getProperty(18).toString(); weatherAfterday = weatherAfterday + "\n 风力:" + detail.getProperty(19).toString() + "\n" ; iconAfterday[0] = parseIcon(detail.getProperty(20).toString()); iconAfterday[1] = parseIcon(detail.getProperty(21).toString()); // 更新当天的天气实况 textWeatherCurrent .setText(weatherCurrent); // 更新显示今天天气的图标和文本框 textWeatherToday .setText(weatherToday); todayWhIcon1 .setImageResource(iconToday[0]); todayWhIcon2 .setImageResource(iconToday[1]); // 更新显示明天天气的图标和文本框 textWeatherTomorrow .setText(weatherTomorrow); tomorrowWhIcon1 .setImageResource(iconTomorrow[0]); tomorrowWhIcon2 .setImageResource(iconTomorrow[1]); // 更新显示后天天气的图标和文本框 textWeatherAfterday .setText(weatherAfterday); afterdayWhIcon1 .setImageResource(iconAfterday[0]); afterdayWhIcon2 .setImageResource(iconAfterday[1]); }
// 工具方法,该方法负责把返回的天气图标字符串,转换为程序的图片资源ID。
private int parseIcon(String strIcon) { if (strIcon == null ) return -1; if ( "0.gif" .equals(strIcon)) return R.drawable. a_0 ; if ( "1.gif" .equals(strIcon)) return R.drawable. a_1 ; if ( "2.gif" .equals(strIcon)) return R.drawable. a_2 ; if ( "3.gif" .equals(strIcon)) return R.drawable. a_3 ; if ( "4.gif" .equals(strIcon)) return R.drawable. a_4 ; if ( "5.gif" .equals(strIcon)) return R.drawable. a_5 ; if ( "6.gif" .equals(strIcon)) return R.drawable. a_6 ; if ( "7.gif" .equals(strIcon)) return R.drawable. a_7 ; if ( "8.gif" .equals(strIcon)) return R.drawable. a_8 ; if ( "9.gif" .equals(strIcon)) return R.drawable. a_9 ; if ( "10.gif" .equals(strIcon)) return R.drawable. a_10 ; if ( "11.gif" .equals(strIcon)) return R.drawable. a_11 ; if ( "12.gif" .equals(strIcon)) return R.drawable. a_12 ; if ( "13.gif" .equals(strIcon)) return R.drawable. a_13 ; if ( "14.gif" .equals(strIcon)) return R.drawable. a_14 ; if ( "15.gif" .equals(strIcon)) return R.drawable. a_15 ; if ( "16.gif" .equals(strIcon)) return R.drawable. a_16 ; if ( "17.gif" .equals(strIcon)) return R.drawable. a_17 ; if ( "18.gif" .equals(strIcon)) return R.drawable. a_18 ; if ( "19.gif" .equals(strIcon)) return R.drawable. a_19 ; if ( "20.gif" .equals(strIcon)) return R.drawable. a_20 ; if ( "21.gif" .equals(strIcon)) return R.drawable. a_21 ; if ( "22.gif" .equals(strIcon)) return R.drawable. a_22 ; if ( "23.gif" .equals(strIcon)) return R.drawable. a_23 ; if ( "24.gif" .equals(strIcon)) return R.drawable. a_24 ; if ( "25.gif" .equals(strIcon)) return R.drawable. a_25 ; if ( "26.gif" .equals(strIcon)) return R.drawable. a_26 ; if ( "27.gif" .equals(strIcon)) return R.drawable. a_27 ; if ( "28.gif" .equals(strIcon)) return R.drawable. a_28 ; if ( "29.gif" .equals(strIcon)) return R.drawable. a_29 ; if ( "30.gif" .equals(strIcon)) return R.drawable. a_30 ; if ( "31.gif" .equals(strIcon)) return R.drawable. a_31 ; return 0; }
|
上面的 Activity 代码己经不再涉及调用 WebService 的代码了,仅仅是简单地调用 Web Service 操作,解析 Web Service 返回的 SOAP 消息包。并把 SOAP 消息包中的数据显示出来。
未完待续..........
原文:http://www.cnblogs.com/lxjshuju/p/7043483.html
内容总结
以上是互联网集市为您收集整理的Android开发之使用Web Service进行网络编程全部内容,希望文章能够帮你解决Android开发之使用Web Service进行网络编程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。