Soru & Cevap

KSoap veri çekme?

09.08.2016 - 09:13

Görsel kaldırıldı.

 

XML bu şekilde. Ben android studio da burdakilerden birini textview e yazdırmak istiyorum ama null geliyor.

Kodları:

package com.example.asus34.akinsoftentegrasyon;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.lang.reflect.Array;

public class MainActivity extends AppCompatActivity {

    private final String NAMESPACE = "http://192.168.56.1/";
    private final String URL = "http://192.168.56.1/WebServis/AkinsoftRaporlar.asmx";
    private final String SOAP_ACTION = "192.168.1.4/CariHareketGetir";
    private final String METHOD_NAME = "CariHareketGetir";
    private String TAG = "PGGURU";
    private static String fahren;
    Button b;
    TextView tv;
    EditText et1;
    EditText et2;
    ListView lv;
    int s1;
    String CariKodu;
    Array myObjectArray;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Celcius Edit Control
        et1 = (EditText) findViewById(R.id.editText1);
        et2 = (EditText) findViewById(R.id.editText2);
        //Fahrenheit Text control
        tv = (TextView) findViewById(R.id.tv_result);
        //Button to trigger web service invocation
        b = (Button) findViewById(R.id.button1);
        lv = (ListView) findViewById(R.id.listView);

        //Button Click Listener
        b.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                //Check if Celcius text control is not empty

                    //Create instance for AsyncCallWS
                    AsyncCallWS task = new AsyncCallWS();
                    //Call execute
                    task.execute();

            }
        });
    }
    private class AsyncCallWS extends AsyncTask<String, Void, Void> {
        @Override
        protected Void doInBackground(String... params) {
            Log.i(TAG, "doInBackground");
           CariHareket();
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            Log.i(TAG, "onPostExecute");

            tv.setText("Sonuc:" + fahren);
        }

        @Override
        protected void onPreExecute() {
            Log.i(TAG, "onPreExecute");
            tv.setText("Hesaplanıyor...");
        }

        @Override
        protected void onProgressUpdate(Void... values) {
            Log.i(TAG, "onProgressUpdate");
        }

    }

    private class MetotCalistir extends AsyncTask<String, Void, Void> {
        @Override
        protected Void doInBackground(String... params) {
            Log.i(TAG, "doInBackground");
            CariHareket();
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            Log.i(TAG, "onPostExecute");
          
        }

        @Override
        protected void onPreExecute() {
            Log.i(TAG, "onPreExecute");
            tv.setText("Hesaplanıyor...");
        }

        @Override
        protected void onProgressUpdate(Void... values) {
            Log.i(TAG, "onProgressUpdate");
        }

    }

    public void CariHareket()
    {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        //Property which holds input parameters
        PropertyInfo Cari1 = new PropertyInfo();
        //Set Name
        Cari1.setName("Carikodu");
        //Set Value
        Cari1.setValue(CariKodu);
        //Set dataType
        Cari1.setType(String.class);
        //Add the property to request object
        request.addProperty(Cari1);
        //Create envelope
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        //Set output SOAP object
        envelope.setOutputSoapObject(request);
        //Create HTTP call object
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        try {
            //Invole web service
            androidHttpTransport.call(SOAP_ACTION, envelope);
            //Get the response
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            //Assign it to fahren static variable
            fahren = response.toString();
            tv.setText(response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    

}

 

216 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

Profile picture for user ekremduvarbasi
ekremduvarbasi
09.08.2016 - 02:38

SoapPrimitive değişkeni response sadece tek bir primitive veriden(string,int,bool gibi) oluşuyorsa kullanılır. Buradaki servisin respoonseu CariHareket dizisi. Bu responseu okumak için response değişkneinin tipi SoapObject olmalı veriyi de ona göre çekmelisin. Örnek olarak bunu verebilirim.

VerifyEmailResults object = new VerifyEmailResults();
try {
            transportSE.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject) envelope.bodyIn;
			
			final int size=response.getPropertyCount();
			for(int i=0;i<size;i++){
			
				SoapObject child=(SoapObject)response.getProperty(i);
				
				if (child.hasProperty("ResponseText")) {
					if (child.getPropertyAsString("ResponseText") == null) {
						object.setResponseText(null);
					} else {
						object.setResponseText(child.getPropertyAsString("ResponseText"));
					}
				}

				if (child.hasProperty("ResponseCode")) {
					if (child.getPropertyAsString("ResponseCode") == null) {
						object.setResponseCode(-1);
					} else {
						object.setResponseCode(Integer.parseInt(child.getPropertyAsString("ResponseCode")));
					}
				}

				if (child.hasProperty("LastMailServer")) {
					if (child.getPropertyAsString("LastMailServer") == null) {
						object.setLastMailServer(null);
					} else {
						object.setLastMailServer(child.getPropertyAsString("LastMailServer"));
					}
				}

				if (child.hasProperty("GoodEmail")) {
					if (child.getPropertyAsString("GoodEmail") == null) {
						object.setGoodEmail(false);
					} else {
						object.setGoodEmail(Boolean.parseBoolean(child.getPropertyAsString("GoodEmail")));
					}
				}
			}
        } catch (Exception e) {
            e.printStackTrace();
        }

 

Eğer bu işe yaramazsa sorun SOAP_ACTION değişkeninde olabilir. Daha önce böyle bir sorunla karşılaşmıştım Soap Action değerini tutan değişkenimi

SOAP_ACTION = NAMESPACE + "/" + METHOD_NAME

şeklinde ayarlayarak sorunumu çözmüştüm.