Android

mail@pastecode.io avatar
unknown
java
3 years ago
2.2 kB
1
Indexable
Never
package com.example.projekt_stm;

import androidx.appcompat.app.AppCompatActivity;

import android.net.ConnectivityManager;
import android.os.Bundle;
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.ksoap2.serialization.PropertyInfo;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;


public class MainActivity extends AppCompatActivity {

    private static final String NAMESPACE = "http://eti.pg/";
    private static String URL="http://192.168.1.39:8080/ProjektSTM/ProjektWS?WSDL"; //192.168.1.39
    private static final String METHOD_NAME = "hello";
    private static final String SOAP_ACTION = "http://192.168.1.39:8080/ProjektSTM/ProjektWS/hello"; //http://192.168.1.39:8080/ProjektSTM/ProjektWS

    private TextView lblResult;

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

        lblResult = (TextView) findViewById(R.id.result);
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        PropertyInfo propInfo = new PropertyInfo();
        propInfo.name = "arg0";
        propInfo.type = PropertyInfo.STRING_CLASS;
        request.addProperty(propInfo.name, "John Smith");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        try {
            lblResult.setText("ETAP_1");
            androidHttpTransport.call(NAMESPACE+METHOD_NAME, envelope);
            lblResult.setText("ETAP_2");
            SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
            lblResult.setText(resultsRequestSOAP.toString());
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        catch (XmlPullParserException e) {
            e.printStackTrace();
        }

    }
}