ANDROID使用ksop2未获取数据
我在调用网络服务时遇到问题。我的服务器上有一个 .NET Web 服务,数据采用 Xml 格式,我需要从那里检索值,并且我在 android 2.2 Galaxy 附加组件中使用 KSOAP2(2.5.4 jar 文件)。运行程序时,它显示强制关闭警报消息。下面是我的代码,请检查...
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.widget.TextView;
public class SoapActivity extends Activity
{
private static String SOAP_ACTION = "http://tempuri.org/GetLabResults";
private static String NAMESPACE = "http://tempuri.org/ ";
private static String METHOD_NAME = "GetLabResults";
private static String URL = "http://192.168.1.19/MOBILETEST/service1.asmx?op=GetLabResults";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("ReportDate","10-11-2011 10:10");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
// Make the soap call.
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
} catch (Exception e) {
e.printStackTrace();
}
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
// SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
// String strRes = result.toString();
if(result != null){
TextView t = (TextView)this.findViewById(R.id.resultbox);
t.setText("SOAP response:\n\n" + result.getProperty(0).toString());
}
}
}
I have a problem while calling a webservice. I have a .NET web service on the server and the data is in Xml format i need to retreive value from there, and I am using KSOAP2 (2.5.4 jar file)in android 2.2 galaxy add-on. While running the program it is showing force close alert message.here is my code below please check it...
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.widget.TextView;
public class SoapActivity extends Activity
{
private static String SOAP_ACTION = "http://tempuri.org/GetLabResults";
private static String NAMESPACE = "http://tempuri.org/ ";
private static String METHOD_NAME = "GetLabResults";
private static String URL = "http://192.168.1.19/MOBILETEST/service1.asmx?op=GetLabResults";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("ReportDate","10-11-2011 10:10");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
// Make the soap call.
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
} catch (Exception e) {
e.printStackTrace();
}
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
// SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
// String strRes = result.toString();
if(result != null){
TextView t = (TextView)this.findViewById(R.id.resultbox);
t.setText("SOAP response:\n\n" + result.getProperty(0).toString());
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一些关于这个东西的博客文章。当您尝试使用 kSOAP2 和 Android 时,它可能会对您有所帮助。
http://roderickbarnes.com/blog/category/technology/web-services-technology
我希望这有帮助。
I have a few blog entries on this stuff. It may be of help to you as you try to work with kSOAP2 and Android.
http://roderickbarnes.com/blog/category/technology/web-services-technology
I hope this helps.