我浏览了很多关于使用 android 使用 .net Web 服务的文章,但似乎我无法让它工作。
我已经下载了“ksoap2-android-assembly-2.6.2-jar-with-dependencies” 并将其作为外部 jar 添加到我当前的项目中。
我已经将 uses-permission android:name="android.permission.INTERNET"放在清单文件中。
当我调试程序并调用该函数时,应用程序说“应用程序* (* ) 已意外停止。请重试。”
我究竟做错了什么?这是我的代码:
private static final String NAMESPACE = "http://epson.com.ph/";
private static final String SOAP_ACTION = "http://epson.com.ph/TheMessage";
private static final String METHOD_NAME = "TheMessage";
private static final String URL = "http://10.0.2.2/DataAccess.asmx";
private void getData(){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//request.addProperty("selectStatement", "SELECT * FROM ALLDETAILS");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
TextView tv = (TextView)findViewById(R.id.txtPreview);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = (Object)envelope.getResponse();
tv.setText(result.toString());
} catch (Exception ex) {
messageBox(ex.getMessage());
}
}
logcat 错误是:
04-10 11:04:46.156: E/AndroidRuntime(332): FATAL EXCEPTION: main
04-10 11:04:46.156: E/AndroidRuntime(332): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
04-10 11:04:46.156: E/AndroidRuntime(332): at my.WSCA.WebServiceConsumptionActivity.getData(WebServiceConsumptionActivity.java:53)
04-10 11:04:46.156: E/AndroidRuntime(332): at my.WSCA.WebServiceConsumptionActivity.access$0(WebServiceConsumptionActivity.java:52)
04-10 11:04:46.156: E/AndroidRuntime(332): at my.WSCA.WebServiceConsumptionActivity$1.onClick(WebServiceConsumptionActivity.java:42)
04-10 11:04:46.156: E/AndroidRuntime(332): at android.view.View.performClick(View.java:2485)
04-10 11:04:46.156: E/AndroidRuntime(332): at android.view.View$PerformClick.run(View.java:9080)
04-10 11:04:46.156: E/AndroidRuntime(332): at android.os.Handler.handleCallback(Handler.java:587)
04-10 11:04:46.156: E/AndroidRuntime(332): at android.os.Handler.dispatchMessage(Handler.java:92)
04-10 11:04:46.156: E/AndroidRuntime(332): at android.os.Looper.loop(Looper.java:123)
04-10 11:04:46.156: E/AndroidRuntime(332): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-10 11:04:46.156: E/AndroidRuntime(332): at java.lang.reflect.Method.invokeNative(Native Method)
04-10 11:04:46.156: E/AndroidRuntime(332): at java.lang.reflect.Method.invoke(Method.java:507)
04-10 11:04:46.156: E/AndroidRuntime(332): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-10 11:04:46.156: E/AndroidRuntime(332): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-10 11:04:46.156: E/AndroidRuntime(332): at dalvik.system.NativeStart.main(Native Method)
请帮助我,我需要尽快完成这项工作。谢谢!