如何通过 kSOAP 2 从 .net Web 服务获取数据
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你添加了 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.
从以下链接下载 KSOAP2 jar 文件:
https://oss.sonatype.org/content/repositories/ksoap2-android-releases/com/google/code/ksoap2-android/ksoap2-android- assembly/2.6.0/ksoap2-android- assembly-2.6 .0-jar-with-dependency.jar
将下载的 jar 文件添加到项目的 libs 文件夹中。
Download KSOAP2 jar file from the following link:
https://oss.sonatype.org/content/repositories/ksoap2-android-releases/com/google/code/ksoap2-android/ksoap2-android-assembly/2.6.0/ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar
Add the downloaded jar file in libs folder in your project.