下文来自:
http://www.ibm.com/developerworks/webservices/library/ws-android/index.html ----- (主要讲解 wsdl格式的访问)
http://blog.163.com/wkai2009@126/blog/static/120177812201071161820/
---------------------------------------------------------------------------------------------------------
android如何访问webservices
在DevDiv中我提过这个问题,非常感谢各位朋友给我提供的资料。经过整理测试现在我整理出来给大家共享 android通过KSOP2访问asmx和wsdl 1.下载ksoap2-android-assembly-2.4-jar-with-dependencies.jar(138m).并加载到工程libraries中。 2.由于android默认是禁用soket所以在开始之前需要修改AndroidManifest.xml。添加: 3.导入包: import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; 3.1wsdl的连接: SoapObject request = new SoapObject("http://172.16.2.53:8080/j2me_webservice1/services/hello", "getHello"); request.addProperty( "name", "name" ); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.bodyOut = request; HttpTransportSE ht = new HttpTransportSE("http://172.16.2.53:8080/j2me_webservice1/services/hello?wsdl"); try { ht.call(null, envelope); Object Response = envelope.getResult(); MessageBox(Toast.LENGTH_SHORT,Response.toString()); } catch(Exception ex) { MessageBox(Toast.LENGTH_SHORT,ex.getMessage().toString()); } 3.2 asmx连接 String nameSpace = "http://tempuri.org/"; String serviceURL = "http://172.16.2.40/FullerTon/WebService.asmx"; String methodName = "CheckUer"; String soapAction = "http://tempuri.org/CheckUer"; SoapObject request = new SoapObject(nameSpace, methodName); request.addProperty("UserNum", "111"); request.addProperty("UserPwd", ""); request.addProperty("PdaNum", "111"); request.addProperty("SyncNum", "5.0"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.bodyOut = request; envelope.dotNet=true; HttpTransportSE ht = new HttpTransportSE(serviceURL); ht.debug = true; try { ht.call(soapAction, envelope); if (envelope.getResponse() != null) { return envelope.getResponse().toString(); } else { return "null"; } } catch (Exception e) { e.printStackTrace(); return "err"; } 说明:其中nameSpace,soapAction 。用浏览器打开的你的webservice 中都可以找到