ANDROID使用kso​​p2未获取数据

发布于 2024-12-11 05:19:09 字数 2118 浏览 0 评论 0原文

我在调用网络服务时遇到问题。我的服务器上有一个 .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 技术交流群。

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

发布评论

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

评论(1

隱形的亼 2024-12-18 05:19:09

我有一些关于这个东西的博客文章。当您尝试使用 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.

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