Today I will explain to you how to load data using soap. Soap is not much used today but it has its own features like security so it is used even today
Points to Note
SOAP is a communication protocol designed to communicate via Internet.
SOAP can extend HTTP for XML messaging.
SOAP provides data transport for Web services.
SOAP can exchange complete documents or call a remote procedure.
SOAP can be used for broadcasting a message.
SOAP is platform- and language-independent.
SOAP is the XML way of defining what information is sent and how.
SOAP enables client applications to easily connect to remote services and invoke remote methods.
Manifest file
Java file
Xml file
Points to Note
SOAP is a communication protocol designed to communicate via Internet.
SOAP can extend HTTP for XML messaging.
SOAP provides data transport for Web services.
SOAP can exchange complete documents or call a remote procedure.
SOAP can be used for broadcasting a message.
SOAP is platform- and language-independent.
SOAP is the XML way of defining what information is sent and how.
SOAP enables client applications to easily connect to remote services and invoke remote methods.
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vishalsingh.soap">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Java file
package com.vishalsingh.soap;
import android.content.Context;
import android.os.AsyncTask;
import android.os.PowerManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
SoapObject result;
Workertask workertask;
TextView textView;
String mytext;
String SchId;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textview);
workertask = new Workertask();
workertask.execute();
}
private class Workertask extends AsyncTask {
String[] separated;
int count = 0;
String authenticated;
@Override
protected Object doInBackground(Object[] objects) {
String SOAP_ACTION = "Your Soap Action";
String NAMESPACE = "Your namespace";
String METHOD_NAME = "your method";
String URL = "your url";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("un", "sumit");
request.addProperty("pass", "billy");
request.addProperty("DeviceId", "00");
request.addProperty("Technology", "android");
request.addProperty("ISNew", "0");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
result = (SoapObject) envelope.bodyIn;
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace(); }
count = result.getPropertyCount();
authenticated = result.getProperty(0).toString();
separated = new String[count];
separated = (authenticated).split("%");
SchId = separated[0];
String SchName = separated[1];
String fName = separated[2];
return null;
}
@Override
protected void onPostExecute(Object o) {
textView.setText(SchId);
super.onPostExecute(o);
} } }
Xml file
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>