Monday, June 4, 2012

web services soap request example


web services soap request example 

import java.io.IOException;
import java.net.UnknownHostException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Log;

public class SoapService {
// for local usage use this IP
// private static final String URL = "http://192.168.55.213:8080/axis2/services/AndroidRemoteService?wsdl";

// for remote usage
// private static final String URL = "http://118.102.133.197:8080/axis2/services/AndroidRemoteService?wsdl";

private static final String URL = "http://182.18.156.227:8080/axis2/services/AndroidRemoteService?wsdl";


// private static final String URL = "http://hmrifinance.co.cc/axis2/services/AVTSRemoteService?wsdl";
// private static final String URL
// ="http://192.168.55.33:8085/axis2/services/AVTSRemoteService?wsdl";
// private static final String URL =
// "http://192.168.55.217/axis2/services/AVTSRemoteService?wsdl";
private static final String NAMESPACE = "http://remote.avts.zoltit";
private static final String SOAP_ACTION = "urn:androidservice";
private static final String METHOD_NAME = "androidservice";
private static String result = null;

int caseNumber;
String xmlData;
String loginId;

public String SoapService(int caseNumber, String xmlData, String loginId) {

this.caseNumber = caseNumber;
this.xmlData = xmlData;
this.loginId = loginId;

Log.v("SOAP SERVICE P1", "" + this.caseNumber);
Log.v("SOAP SERVICE P2", "" + this.xmlData);
Log.v("SOAP SERVICE P3", "" + this.loginId);

SoapObject soap_object = new SoapObject(NAMESPACE, METHOD_NAME);

soap_object.addProperty("caseNumber", caseNumber);
soap_object.addProperty("xmldata", xmlData);
soap_object.addProperty("loginid", loginId);

SoapSerializationEnvelope soap_envelop = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
soap_envelop.setOutputSoapObject(soap_object);

AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);

try {
httpTransport.call(SOAP_ACTION, soap_envelop);
} catch (UnknownHostException e1) {
e1.printStackTrace();
ApplicationVariables.error = 100;
}  catch (NullPointerException e1) {
e1.printStackTrace();
ApplicationVariables.error = 123;
} catch (IOException e1) {
ApplicationVariables.error = 0;
e1.printStackTrace();
} catch (XmlPullParserException e1) {
ApplicationVariables.error = 0;
e1.printStackTrace();
} catch (Exception e) {
ApplicationVariables.error = 0;
}

try {
result = soap_envelop.getResponse().toString();
System.out.println("Result "+result);
// Log.v("Result", "Result........... " + result);
} catch (SoapFault e) {
e.printStackTrace();
} catch (NullPointerException e1) {
ApplicationVariables.error = 123;
e1.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}

return result;
}
}



No comments:

Post a Comment