Skip to content

Instantly share code, notes, and snippets.

@gokhanaliccii
Created December 11, 2014 06:14
Show Gist options
  • Save gokhanaliccii/06979d324b504e852d39 to your computer and use it in GitHub Desktop.
Save gokhanaliccii/06979d324b504e852d39 to your computer and use it in GitHub Desktop.
Example of using xml based services at android with ksoap library
package com.example.zsoop;
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView resultText;
String SOAP_ACTION = "http://tempuri.org/UserControl";
String NAMESPACE = "http://tempuri.org/";
String METHOD_NAME = "UserControl";
String URL = "http://168.62.217.166/IzgazMobileSrv.asmx";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultText=(TextView)findViewById(R.id.s);
SoapObject object=new SoapObject(NAMESPACE, METHOD_NAME);
object.addProperty("clientid", "40");
object.addProperty("password","fd");
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(object);
AndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
} catch (IOException e1) {
resultText.setText("Fail :" + e1.toString());
e1.printStackTrace();
} catch (XmlPullParserException e1) {
resultText.setText("Fail :" + e1.toString());
e1.printStackTrace();
}
try {
SoapPrimitive primitive=(SoapPrimitive)envelope.getResponse();
SoapObject yazi=(SoapObject)envelope.bodyIn;
resultText.setText(yazi.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment