ksoap2 101 如何

发布于 2024-10-14 15:42:38 字数 5048 浏览 5 评论 0原文

下面的代码似乎使我的应用程序崩溃

不知道为什么

帮助赞赏。

final String SOAP_ACTION = "http://tempuri.org/MyFunction";
    final String METHOD_NAME = "MyFunction";
    final String NAMESPACE = "http://tempuri.org/";
    final String URL = "http://localhost:23250/WS1.asmx";
    final SoapObject requestObject = new SoapObject(NAMESPACE, METHOD_NAME);
    requestObject.addProperty("UserIdentifier", "");
    requestObject.addProperty("PhoneIdentifier", "");

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(requestObject);

    try
    {
        HttpTransport androidHttpTransport = new HttpTransport(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapObject response = (SoapObject)envelope.getResponse();
        String result =  response.getProperty(0).toString();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

我可以从浏览器调用 Web 服务,

下面是 LogCat 数据

01-27 09:29:49.564: DEBUG/dalvikvm(296): GC_EXPLICIT freed 307 objects / 16416 bytes in 169ms
01-27 09:29:55.555: INFO/ActivityManager(106): Starting activity: Intent { cmp=myapp.android.v2/.myPage }
01-27 09:29:56.035: INFO/dalvikvm(1074): Could not find method javax.microedition.io.Connector.open, referenced from method org.ksoap2.transport.ServiceConnectionMidp.<init>
01-27 09:29:56.035: WARN/dalvikvm(1074): VFY: unable to resolve static method 113: Ljavax/microedition/io/Connector;.open (Ljava/lang/String;IZ)Ljavax/microedition/io/Connection;
01-27 09:29:56.035: DEBUG/dalvikvm(1074): VFY: replacing opcode 0x71 at 0x0005
01-27 09:29:56.035: DEBUG/dalvikvm(1074): VFY: dead code 0x0008-000d in Lorg/ksoap2/transport/ServiceConnectionMidp;.<init> (Ljava/lang/String;)V
01-27 09:29:56.055: INFO/dalvikvm(1074): Could not find method javax.microedition.io.HttpConnection.close, referenced from method org.ksoap2.transport.ServiceConnectionMidp.disconnect
01-27 09:29:56.055: WARN/dalvikvm(1074): VFY: unable to resolve interface method 114: Ljavax/microedition/io/HttpConnection;.close ()V
01-27 09:29:56.065: DEBUG/dalvikvm(1074): VFY: replacing opcode 0x72 at 0x0002
01-27 09:29:56.065: DEBUG/dalvikvm(1074): VFY: dead code 0x0005-0005 in Lorg/ksoap2/transport/ServiceConnectionMidp;.disconnect ()V
01-27 09:29:56.085: INFO/dalvikvm(1074): Could not find method javax.microedition.io.HttpConnection.openInputStream, referenced from method org.ksoap2.transport.ServiceConnectionMidp.openInputStream
01-27 09:29:56.085: WARN/dalvikvm(1074): VFY: unable to resolve interface method 115: Ljavax/microedition/io/HttpConnection;.openInputStream ()Ljava/io/InputStream;
01-27 09:29:56.085: DEBUG/dalvikvm(1074): VFY: replacing opcode 0x72 at 0x0002
01-27 09:29:56.095: DEBUG/dalvikvm(1074): VFY: dead code 0x0005-0006 in Lorg/ksoap2/transport/ServiceConnectionMidp;.openInputStream ()Ljava/io/InputStream;
01-27 09:29:56.115: INFO/dalvikvm(1074): Could not find method javax.microedition.io.HttpConnection.openOutputStream, referenced from method org.ksoap2.transport.ServiceConnectionMidp.openOutputStream
01-27 09:29:56.115: WARN/dalvikvm(1074): VFY: unable to resolve interface method 116: Ljavax/microedition/io/HttpConnection;.openOutputStream ()Ljava/io/OutputStream;
01-27 09:29:56.115: DEBUG/dalvikvm(1074): VFY: replacing opcode 0x72 at 0x0002
01-27 09:29:56.115: DEBUG/dalvikvm(1074): VFY: dead code 0x0005-0006 in Lorg/ksoap2/transport/ServiceConnectionMidp;.openOutputStream ()Ljava/io/OutputStream;
01-27 09:29:56.135: INFO/dalvikvm(1074): Could not find method javax.microedition.io.HttpConnection.setRequestMethod, referenced from method org.ksoap2.transport.ServiceConnectionMidp.setRequestMethod
01-27 09:29:56.135: WARN/dalvikvm(1074): VFY: unable to resolve interface method 117: Ljavax/microedition/io/HttpConnection;.setRequestMethod (Ljava/lang/String;)V
01-27 09:29:56.145: DEBUG/dalvikvm(1074): VFY: replacing opcode 0x72 at 0x0002
01-27 09:29:56.145: DEBUG/dalvikvm(1074): VFY: dead code 0x0005-0005 in Lorg/ksoap2/transport/ServiceConnectionMidp;.setRequestMethod (Ljava/lang/String;)V
01-27 09:29:56.165: INFO/dalvikvm(1074): Could not find method javax.microedition.io.HttpConnection.setRequestProperty, referenced from method org.ksoap2.transport.ServiceConnectionMidp.setRequestProperty
01-27 09:29:56.165: WARN/dalvikvm(1074): VFY: unable to resolve interface method 118: Ljavax/microedition/io/HttpConnection;.setRequestProperty (Ljava/lang/String;Ljava/lang/String;)V
01-27 09:29:56.165: DEBUG/dalvikvm(1074): VFY: replacing opcode 0x72 at 0x0002
01-27 09:29:56.175: DEBUG/dalvikvm(1074): VFY: dead code 0x0005-0005 in Lorg/ksoap2/transport/ServiceConnectionMidp;.setRequestProperty (Ljava/lang/String;Ljava/lang/String;)V
01-27 09:30:05.580: WARN/ActivityManager(106): Launch timeout has expired, giving up wake lock!
01-27 09:30:05.796: WARN/ActivityManager(106): Activity idle timeout for HistoryRecord{4405ce08 myapp.android.v2/.myPage}

The code below seems to crash my app

Not sure why

Help appreciated.

final String SOAP_ACTION = "http://tempuri.org/MyFunction";
    final String METHOD_NAME = "MyFunction";
    final String NAMESPACE = "http://tempuri.org/";
    final String URL = "http://localhost:23250/WS1.asmx";
    final SoapObject requestObject = new SoapObject(NAMESPACE, METHOD_NAME);
    requestObject.addProperty("UserIdentifier", "");
    requestObject.addProperty("PhoneIdentifier", "");

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(requestObject);

    try
    {
        HttpTransport androidHttpTransport = new HttpTransport(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapObject response = (SoapObject)envelope.getResponse();
        String result =  response.getProperty(0).toString();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

I can call the webservice from my browser just fine

Below is the LogCat data

01-27 09:29:49.564: DEBUG/dalvikvm(296): GC_EXPLICIT freed 307 objects / 16416 bytes in 169ms
01-27 09:29:55.555: INFO/ActivityManager(106): Starting activity: Intent { cmp=myapp.android.v2/.myPage }
01-27 09:29:56.035: INFO/dalvikvm(1074): Could not find method javax.microedition.io.Connector.open, referenced from method org.ksoap2.transport.ServiceConnectionMidp.<init>
01-27 09:29:56.035: WARN/dalvikvm(1074): VFY: unable to resolve static method 113: Ljavax/microedition/io/Connector;.open (Ljava/lang/String;IZ)Ljavax/microedition/io/Connection;
01-27 09:29:56.035: DEBUG/dalvikvm(1074): VFY: replacing opcode 0x71 at 0x0005
01-27 09:29:56.035: DEBUG/dalvikvm(1074): VFY: dead code 0x0008-000d in Lorg/ksoap2/transport/ServiceConnectionMidp;.<init> (Ljava/lang/String;)V
01-27 09:29:56.055: INFO/dalvikvm(1074): Could not find method javax.microedition.io.HttpConnection.close, referenced from method org.ksoap2.transport.ServiceConnectionMidp.disconnect
01-27 09:29:56.055: WARN/dalvikvm(1074): VFY: unable to resolve interface method 114: Ljavax/microedition/io/HttpConnection;.close ()V
01-27 09:29:56.065: DEBUG/dalvikvm(1074): VFY: replacing opcode 0x72 at 0x0002
01-27 09:29:56.065: DEBUG/dalvikvm(1074): VFY: dead code 0x0005-0005 in Lorg/ksoap2/transport/ServiceConnectionMidp;.disconnect ()V
01-27 09:29:56.085: INFO/dalvikvm(1074): Could not find method javax.microedition.io.HttpConnection.openInputStream, referenced from method org.ksoap2.transport.ServiceConnectionMidp.openInputStream
01-27 09:29:56.085: WARN/dalvikvm(1074): VFY: unable to resolve interface method 115: Ljavax/microedition/io/HttpConnection;.openInputStream ()Ljava/io/InputStream;
01-27 09:29:56.085: DEBUG/dalvikvm(1074): VFY: replacing opcode 0x72 at 0x0002
01-27 09:29:56.095: DEBUG/dalvikvm(1074): VFY: dead code 0x0005-0006 in Lorg/ksoap2/transport/ServiceConnectionMidp;.openInputStream ()Ljava/io/InputStream;
01-27 09:29:56.115: INFO/dalvikvm(1074): Could not find method javax.microedition.io.HttpConnection.openOutputStream, referenced from method org.ksoap2.transport.ServiceConnectionMidp.openOutputStream
01-27 09:29:56.115: WARN/dalvikvm(1074): VFY: unable to resolve interface method 116: Ljavax/microedition/io/HttpConnection;.openOutputStream ()Ljava/io/OutputStream;
01-27 09:29:56.115: DEBUG/dalvikvm(1074): VFY: replacing opcode 0x72 at 0x0002
01-27 09:29:56.115: DEBUG/dalvikvm(1074): VFY: dead code 0x0005-0006 in Lorg/ksoap2/transport/ServiceConnectionMidp;.openOutputStream ()Ljava/io/OutputStream;
01-27 09:29:56.135: INFO/dalvikvm(1074): Could not find method javax.microedition.io.HttpConnection.setRequestMethod, referenced from method org.ksoap2.transport.ServiceConnectionMidp.setRequestMethod
01-27 09:29:56.135: WARN/dalvikvm(1074): VFY: unable to resolve interface method 117: Ljavax/microedition/io/HttpConnection;.setRequestMethod (Ljava/lang/String;)V
01-27 09:29:56.145: DEBUG/dalvikvm(1074): VFY: replacing opcode 0x72 at 0x0002
01-27 09:29:56.145: DEBUG/dalvikvm(1074): VFY: dead code 0x0005-0005 in Lorg/ksoap2/transport/ServiceConnectionMidp;.setRequestMethod (Ljava/lang/String;)V
01-27 09:29:56.165: INFO/dalvikvm(1074): Could not find method javax.microedition.io.HttpConnection.setRequestProperty, referenced from method org.ksoap2.transport.ServiceConnectionMidp.setRequestProperty
01-27 09:29:56.165: WARN/dalvikvm(1074): VFY: unable to resolve interface method 118: Ljavax/microedition/io/HttpConnection;.setRequestProperty (Ljava/lang/String;Ljava/lang/String;)V
01-27 09:29:56.165: DEBUG/dalvikvm(1074): VFY: replacing opcode 0x72 at 0x0002
01-27 09:29:56.175: DEBUG/dalvikvm(1074): VFY: dead code 0x0005-0005 in Lorg/ksoap2/transport/ServiceConnectionMidp;.setRequestProperty (Ljava/lang/String;Ljava/lang/String;)V
01-27 09:30:05.580: WARN/ActivityManager(106): Launch timeout has expired, giving up wake lock!
01-27 09:30:05.796: WARN/ActivityManager(106): Activity idle timeout for HistoryRecord{4405ce08 myapp.android.v2/.myPage}

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

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

发布评论

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

评论(4

风吹过旳痕迹 2024-10-21 15:42:38

您需要下载j2se版本而不是j2me版本。

You need to download the j2se version instead of the j2me version.

似最初 2024-10-21 15:42:38

当我尝试调试我的应用程序时也出现了同样的错误。我能够通过重新链接 KSOAP2 SE 库而不是使用 me 版本来纠正它。

The same error appeared while I was trying to debug my app as well. I was able to correct it by re-linking the KSOAP2 SE Library instead of using the me edition.

爱给你人给你 2024-10-21 15:42:38

我遇到了同样的错误,我必须清除 Java 构建路径中除 Android #.# 之外的所有条目(其中 #.# 是您在项目中使用的版本号)。然后我清理了项目(Project,Clean),一切似乎都正常。

I had the same error in which I had to clear all the entries from the Java Build Path except for the Android #.# (where #.# is the version number you are working with in your project). I then cleaned the project (Project, Clean) and all seemed to work.

又爬满兰若 2024-10-21 15:42:38

事实证明这是一个程序员错误,

我调用了一个不存在的 webmethod。

没有名为 MyFunction 的方法

Turns out it was a programmer error

I was calling a webmethod that did not exist.

There was no method called MyFunction

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