Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.0 kB
2
Indexable
Never
package com.example.controlcalidad;

import androidx.appcompat.app.AppCompatActivity;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

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 org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;

public class MainActivity extends AppCompatActivity {

    EditText numPartida;
    Button btnConsulta;
    TextView resultado;

    private String numParti;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        numPartida = (EditText) findViewById(R.id.editTextNumberSigned);
        btnConsulta = (Button) findViewById(R.id.btnConsultar);
        resultado = (TextView) findViewById(R.id.txtOK);

        btnConsulta.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                numParti = numPartida.getText().toString();

                new AuthTask().execute();

            }
        });
    }

    private class AuthTask extends AsyncTask<Void, Void, String> {

        public static final String NAMESPACE = "http://192.168.0.5:81/webservice.asmx/";
        public static final String METHOD = "ExistePartida";
        public static final String SOAPACTION = "http://192.168.0.5:81/webservice.asmx/ExistePartida";
        public static final String URL = "http://192.168.0.5:81/webservice.asmx?op=ExistePartida";


        @Override
        protected String doInBackground(Void... voids) {

            SoapObject request = new SoapObject(NAMESPACE, METHOD);
            request.addProperty("ExistePartida",resultado);

            SoapSerializationEnvelope envelope =
                    new SoapSerializationEnvelope(SoapEnvelope.VER11);

            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);

            HttpTransportSE transport = new HttpTransportSE(URL);
            try {
                transport.call(SOAPACTION, envelope);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
            }

            SoapObject response = (SoapObject)envelope.bodyIn;
            SoapPrimitive result =
                    (SoapPrimitive) response.getProperty("ExistePartida");



            return result.toString();
        }

        @Override
        protected void onPostExecute(String aBoolean) {
            super.onPostExecute(aBoolean);
            resultado.setText("Resultado es " +  aBoolean);
        }
    }

}