如何通过 kSOAP 2 从 .net Web 服务获取数据

发布于 2024-11-27 09:22:57 字数 1930 浏览 0 评论 0原文

我正在使用 kSoap2 从 WS 获取数据。但我得到的输出是字符串“Error”,而不是值“89.6”。

谁能告诉我下面的代码哪里出了问题?

package net.manoj.MytestServices;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class Main extends Activity { 
private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private static final String METHOD_NAME = "CelsiusToFahrenheit";
private static final String NAMESPACE = "http://www.tempuri.org/";
// private static final String URL = "http://216.128.29.26/webservices/tempconvert.asmx";
private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx"; 
   TextView tv;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    tv = (TextView) findViewById(R.id.textView1);
    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
    Request.addProperty("Celsius", "32");

    SoapSerializationEnvelope SoapEnvelop = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    SoapEnvelop.dotNet = true;
    SoapEnvelop.setOutputSoapObject(Request);
    HttpTransportSE abt = new HttpTransportSE(URL);
    abt.debug = true;

    try {
        abt.call(SOAP_ACTION, SoapEnvelop);
        //SoapPrimitive resultstring = (SoapPrimitive) SoapEnvelop.getResponse();
        SoapObject result = (SoapObject) SoapEnvelop.getResponse();
        Object f = result.toString();
        tv.setText("States : " + f);

      } catch (Exception e) {
        e.printStackTrace();
    }
  }
    }

我没有得到任何例外。有人可以帮我解决这个问题吗?

I am using kSoap2 to get data from WS. But i get the string "Error" as my out put instead of value "89.6".

can any one tell me where i am going wrong in the following code?

package net.manoj.MytestServices;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class Main extends Activity { 
private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private static final String METHOD_NAME = "CelsiusToFahrenheit";
private static final String NAMESPACE = "http://www.tempuri.org/";
// private static final String URL = "http://216.128.29.26/webservices/tempconvert.asmx";
private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx"; 
   TextView tv;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    tv = (TextView) findViewById(R.id.textView1);
    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
    Request.addProperty("Celsius", "32");

    SoapSerializationEnvelope SoapEnvelop = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    SoapEnvelop.dotNet = true;
    SoapEnvelop.setOutputSoapObject(Request);
    HttpTransportSE abt = new HttpTransportSE(URL);
    abt.debug = true;

    try {
        abt.call(SOAP_ACTION, SoapEnvelop);
        //SoapPrimitive resultstring = (SoapPrimitive) SoapEnvelop.getResponse();
        SoapObject result = (SoapObject) SoapEnvelop.getResponse();
        Object f = result.toString();
        tv.setText("States : " + f);

      } catch (Exception e) {
        e.printStackTrace();
    }
  }
    }

i am not getting any exception of this. can any one pls help me on this?

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

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

发布评论

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

评论(2

浪推晚风 2024-12-04 09:22:57

你添加了 KSOAP2 jar 文件吗?

下载此文件并将其添加到您的项目中。

ksoap2-android- assembly-2.5.4-jar-with-dependency.jar

如果此后出现任何错误,请告诉我。

have u added KSOAP2 jar file.

download this file and add it yopur project.

ksoap2-android-assembly-2.5.4-jar-with-dependencies.jar

Let me know in case of any errors after that.

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