android 调用.net 的webservice

    技术2026-06-10  2

    搭建了android环境,第一个需求是调用webservice, 看了一周的教程,至少有2种方法实现1 用java直接socket编程 2调用封装好的ksoap2-android-assembly-2.4-jar-with-dependencies.jar我用第2中方法实现了,步骤1 下载ksoap2-android-assembly-2.4-jar-with-dependencies.jar, 并导入工程     右键工程 -> build path -〉add libraries      ->user library -> user libraries -> new       起一个名字然后 add jars 导入ksoap2的jar2 在AndroidManifest.xml的清单中加入<uses-permission android:name="android.permission.INTERNET" /> 3 为了看到调试的信息 window->show view->logcat 如下图

    4 写入如下代码,运行看Log        Log.v("Debug", "testest");                String nameSpace = "http://tempuri.org/";        String serviceURL = "http://192.168.1.116:12345/Service1.asmx";        String methodName = "HelloWorld";        String soapAction = "http://tempuri.org/HelloWorld";        SoapObject request = new SoapObject(nameSpace, methodName);              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) {                Log.v("HttpRestonse", envelope.getResponse().toString());            } else {             Log.v("HttpRestonse", "NULL");            }        } catch (Exception e) {            e.printStackTrace();            Log.v("HttpRestonseErorr", e.toString());        }log如下02-19 01:08:19.238: VERBOSE/Debug(415): testest

    02-19 01:08:19.517: VERBOSE/HttpRestonse(415): Hello World

    最新回复(0)