Android KSoap2 Webservice使用问题

发布于 2024-10-28 18:36:57 字数 6870 浏览 3 评论 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) ---

我的代码有什么问题?

I am using following code to webservice using Ksoap2

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);
        }
    }
}

but it is giving following output in the 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) ---

What is the problem in my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悟红尘 2024-11-04 18:36:58

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

There are a couple of answers to this question already here. The second link might be your answer if ksoap2 is still sensitive to trailing slashes.

还在原地等你 2024-11-04 18:36:58

这是一个.Net Web服务,您需要

envelope.dotNet = true;

在执行请求之前进行设置。

That's a .Net webservice, you need to set

envelope.dotNet = true;

before executing the request.

南薇 2024-11-04 18:36:58

这不是一个错误,只是关于 kxml2 和 xmlpull 类验证的警告。

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

It is not an error but just warning about kxml2 and xmlpull classes verification.

You are imported ksoap2.jar library for your project to make build. But ksoap2.jar library has a kxml2 and xmlpull jars inside. And these jars already included in Android OS. Therefore DexOpt utility cant verify libraries from your apk binary. Dont worry about it. OS just will use its own kxml2 and xmlpull libraries but not yours.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文