在Android中使用kso​​ap从Web服务获取数据

时间:2014-12-08 09:53:48

标签: android xml android-ksoap2

我正在开发一个项目,我想制作android应用程序,通过soap从Web服务获取数据并解析数据以便在listview中使用。我在查看数据方面遇到了麻烦。使用Log.e()无法在logcat中查看数据。谢谢你的帮助。

我的服务看起来如下链接; http://jsfiddle.net/gkwuvyzs/

这是我的LayerInformation类;

package com.example.soapservice;
public class LayerInformation {

    private String Adi;
    private String Urli;
    private String Lyr_tipi;
    private String Alani;

    public LayerInformation(){
        super();
    }

    public LayerInformation(String Adi, String Urli, String Lyr_tipi, String Alani){
        super();
        this.Adi = Adi;
        this.Urli = Urli;
        this.Lyr_tipi = Lyr_tipi;
        this.Alani = Alani;

    } 

    public String getISMI() {
        return Adi;
      }

      public void setISMI(String Adi) {
        this.Adi = Adi;
      }

      public String getURL() {
        return Urli;
      }

      public void setURL(String Urli) {
        this.Urli = Urli;
      }

      public String getLAYER_TIPI() {
        return Lyr_tipi;
      }

      public void setLAYER_TIPI(String Lyr_tipi) {
        this.Lyr_tipi = Lyr_tipi;
      }

      public String getALANI() {
        return Alani;
      }

      public void setALANI(String Alani) {
        this.Alani = Alani;
      }

      @Override
      public String toString() {
        return "Layer [ISMI=" + Adi + ", URL=" + Urli + ", LAYER_TIPI=" + Lyr_tipi
            + ", ALANI=" + Alani + "]";
      }
}

这是我的主要活动;

public class MainActivity extends Activity {

    final static String METHOD_NAME = "LayerBilgileri";
    final static String NAMESPACE = "http://tempuri.org/";
    final static String SOAP_ACTION = "http://tempuri.org/LayerBilgileri";
    final static String URL = "http://193.34.23.1:84/layerismi/Service1.asmx";
    static String str;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //str = (TextView) findViewById(R.id.textView1);

    }

    public static List<LayerInformation> 
    LayerBilgileri() {
         List<LayerInformation> list = null;
         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
         SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
         envelope.setOutputSoapObject(request);
         HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
         androidHttpTransport.debug = true;

         try {
              androidHttpTransport.call(SOAP_ACTION, envelope);
              SoapObject response = (SoapObject) envelope.getResponse();


              if (response.toString().equals("anyType{}") || response == null) {
                list = null;
              } else {
                SoapObject soapLayerInformationsList = (SoapObject) response.getProperty("LAYERLER");
                // ya da 
                // SoapObject soapLayerInformationsList = (SoapObject) response.getProperty(0);
                list = new ArrayList<LayerInformation>();
                int LayerlerCount = soapLayerInformationsList.getPropertyCount();

                for (int i = 0; i < LayerlerCount; i++) {
                    LayerInformation item = new LayerInformation();
                  SoapObject soapLayerInformations = (SoapObject) soapLayerInformationsList.getProperty(i);

                  if (soapLayerInformations.hasProperty("ISMI")) {
                    item.setISMI(soapLayerInformations.getPropertyAsString("ISMI"));

                  }

                  if (soapLayerInformations.hasProperty("URL")) {
                    item.setURL(soapLayerInformations.getPropertyAsString("URL"));

                  }

                  if (soapLayerInformations.hasProperty("LAYER_TIPI")) {
                    item.setLAYER_TIPI(soapLayerInformations.getPropertyAsString("LAYER_TIPI"));
                  }

                  if (soapLayerInformations.hasProperty("ALANI")) {
                    item.setALANI(soapLayerInformations.getPropertyAsString("ALANI"));
                  }


                  list.add(item);
                }
              }
            } catch (Exception e) {
              e.printStackTrace();
              list = null;
            }

        return list;


    }

0 个答案:

没有答案