0

我正在使用以下代码使用 Ksoap2 进行 Web 服务

package com.google.android.myWebService;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpsTransportSE;
//import org.ksoap2.transport.HttpTransport;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class myWebService extends Activity {
    /** Called when the activity is first created. */
    private static final String SOAP_ACTION = "http://www.webservicex.net/GetWeatherByPlaceName";
    private static final String METHOD_NAME = "GetWeatherByPlaceName";
    private static final String NAMESPACE = "http://www.webservicex.net";
    private static final String URL = "http://www.webservicex.net/WeatherForecast.asmx?WSDL";
    private Object resultsRequestSOAP = null;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        TextView tv = new TextView(this);
        setContentView(tv);

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        // SoapObject
        request.addProperty("PlaceName", "new york");
        //request.addProperty("lastname", "Williams");
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
        Log.d(null,"Status : set HttpTransport");


        HttpsTransportSE androidHttpTransport = new HttpsTransportSE(URL, 443, "", 5000);
        try {
            Log.d(null,"Status : b4 Call");
            androidHttpTransport.call(SOAP_ACTION, envelope);
            Log.d(null,"Status : Call done");
            resultsRequestSOAP = envelope.getResponse();
            Log.d(null,"Status : Response received");
            String[] results = (String[]) resultsRequestSOAP;
            tv.setText(results[0]);
        } catch (Exception aE) {
            //aE.printStackTrace();
            Log.d(null,"Exception: " + aE);
        }
    }
}

但它在 logcat 中给出以下输出:

03-29 16:57:50.961: DEBUG/installd(1096): DexInv: --- BEGIN '/data/app/vmdl42687.tmp' ---
03-29 16:57:51.601: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/xmlpull/v1/XmlPullParser;' has an earlier definition; blocking out
03-29 16:57:51.601: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/io/KXmlParser;' has an earlier definition; blocking out
03-29 16:57:51.601: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/xmlpull/v1/XmlSerializer;' has an earlier definition; blocking out
03-29 16:57:51.611: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/io/KXmlSerializer;' has an earlier definition; blocking out
03-29 16:57:51.611: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/kdom/Node;' has an earlier definition; blocking out
03-29 16:57:51.611: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/kdom/Document;' has an earlier definition; blocking out
03-29 16:57:51.611: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/kdom/Element;' has an earlier definition; blocking out
03-29 16:57:51.611: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/wap/Wbxml;' has an earlier definition; blocking out
03-29 16:57:51.621: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/wap/WbxmlParser;' has an earlier definition; blocking out
03-29 16:57:51.621: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/wap/WbxmlSerializer;' has an earlier definition; blocking out
03-29 16:57:51.621: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/wap/syncml/SyncML;' has an earlier definition; blocking out
03-29 16:57:51.621: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/wap/wml/Wml;' has an earlier definition; blocking out
03-29 16:57:51.621: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/kxml2/wap/wv/WV;' has an earlier definition; blocking out
03-29 16:57:51.621: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/xmlpull/v1/XmlPullParserException;' has an earlier definition; blocking out
03-29 16:57:51.631: DEBUG/dalvikvm(6892): DexOpt: 'Lorg/xmlpull/v1/XmlPullParserFactory;' has an earlier definition; blocking out
03-29 16:57:51.751: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.761: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.761: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.771: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.771: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.771: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.771: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-29 16:57:51.791: INFO/dalvikvm(6892): DexOpt: not resolving ambiguous class 'Lorg/kxml2/io/KXmlSerializer;'
03-29 16:57:51.801: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/xmlpull/v1/XmlPullParser;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/io/KXmlParser;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/xmlpull/v1/XmlSerializer;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/io/KXmlSerializer;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/kdom/Node;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/kdom/Document;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/kdom/Element;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/wap/Wbxml;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/wap/WbxmlParser;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/wap/WbxmlSerializer;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/wap/syncml/SyncML;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/wap/wml/Wml;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/kxml2/wap/wv/WV;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/xmlpull/v1/XmlPullParserException;': multiple definitions
03-29 16:57:51.811: DEBUG/dalvikvm(6892): DexOpt: not verifying 'Lorg/xmlpull/v1/XmlPullParserFactory;': multiple definitions
03-29 16:57:51.821: DEBUG/dalvikvm(6892): DexOpt: load 60ms, verify 186ms, opt 8ms
03-29 16:57:51.881: DEBUG/installd(1096): DexInv: --- END '/data/app/vmdl42687.tmp' (success) ---

我的代码有什么问题?

4

3 回答 3

2

这个问题已经有几个答案了。如果 ksoap2 仍然对尾部斜杠敏感,则第二个链接可能是您的答案。

于 2011-03-29T13:40:56.917 回答
0

那是一个 .Net 网络服务,你需要设置

envelope.dotNet = true;

在执行请求之前。

于 2011-03-29T13:32:03.127 回答
0

这不是错误,而只是警告 kxml2 和 xmlpull 类验证。

您已为您的项目导入 ksoap2.jar 库以进行构建。但是 ksoap2.jar 库里面有一个 kxml2 和 xmlpull 罐子。这些 jars 已经包含在 Android OS 中。因此,DexOpt 实用程序无法验证您的 apk 二进制文件中的库。别担心。操作系统只会使用它自己的 kxml2 和 xmlpull 库,而不是你的。

于 2013-03-27T19:17:25.360 回答