Rectangle 27 0

how to get data from sql server using web service in android?


public class CallSoap 
{

public String SOAP_ACTION = "http://tempuri.org/CreateEvent";

public String OPERATION_NAME = "CreateEvent"; 

public  final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

public String erorr="";

public  final String SOAP_ADDRESS = "http://xxxx/Service1.asmx";

SoapObject request;
SoapSerializationEnvelope envelope;

//AndroidHttpTransport androidHttpTransport;
HttpTransportSE androidHttp;

public CallSoap() 
{ 
}


protected void SetEnvelope() {

    try {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy); 

        // Creating SOAP envelope           
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        //You can comment that line if your web service is not .NET one.
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);
        androidHttp = new HttpTransportSE("xxxx/Service1.asmx");

        androidHttp.debug = true;

    } catch (Exception e) {
        System.out.println("Soap Exception---->>>" + e.toString());    
    }
}

@SuppressLint("SimpldurationFormat")
public int Send(decimal amount, decimal persons)
{
    int id=0;
    try{
            //request
            request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);

            PropertyInfo pi5=new PropertyInfo();
            pi5.setType(decimal.class);
            pi5.setName("amount");
            pi5.setValue(amount);
            request.addProperty(pi5);

            PropertyInfo pi6=new PropertyInfo();
            pi6=new PropertyInfo();
            pi6.setType(decimal.class);
            pi6.setName("persons");
            pi6.setValue(persons);
            request.addProperty(pi6);

            SetEnvelope();
            //Create envelope
        }
    catch (Exception exception)
        {
        erorr= "error:"+exception.toString();
        }
    try
        {
            androidHttp.call(SOAP_ACTION, envelope);
            //Vector<String> result = null;
            //result = (Vector<String>) envelope.getResponse();
            String result = envelope.getResponse().toString();
            try { 
                id=Integer.parseInt(result); 
            } catch(NumberFormatException e) { 
                erorr=result;
            }
        }
    catch (Exception exception)
        {
        erorr= "error:"+exception.toString();
        }
    }
Note
Rectangle 27 0

how to get data from sql server using web service in android?


http://localhost

First and for most thing for you is: You can't make a web API call or can't perform any long running task on main UI directly. FYI, you are making a web call in onCreate() method directly without implementing threading mechanism.

You can implement AsyncTask to resolve this issue.

Note
Rectangle 27 0

how to get data from sql server using web service in android?


http://localhost

First and for most thing for you is: You can't make a web API call or can't perform any long running task on main UI directly. FYI, you are making a web call in onCreate() method directly without implementing threading mechanism.

You can implement AsyncTask to resolve this issue.

Note
Rectangle 27 0

how to get data from sql server using web service in android?


public class CallSoap 
{

public String SOAP_ACTION = "http://tempuri.org/CreateEvent";

public String OPERATION_NAME = "CreateEvent"; 

public  final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

public String erorr="";

public  final String SOAP_ADDRESS = "http://xxxx/Service1.asmx";

SoapObject request;
SoapSerializationEnvelope envelope;

//AndroidHttpTransport androidHttpTransport;
HttpTransportSE androidHttp;

public CallSoap() 
{ 
}


protected void SetEnvelope() {

    try {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy); 

        // Creating SOAP envelope           
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        //You can comment that line if your web service is not .NET one.
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);
        androidHttp = new HttpTransportSE("xxxx/Service1.asmx");

        androidHttp.debug = true;

    } catch (Exception e) {
        System.out.println("Soap Exception---->>>" + e.toString());    
    }
}

@SuppressLint("SimpldurationFormat")
public int Send(decimal amount, decimal persons)
{
    int id=0;
    try{
            //request
            request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);

            PropertyInfo pi5=new PropertyInfo();
            pi5.setType(decimal.class);
            pi5.setName("amount");
            pi5.setValue(amount);
            request.addProperty(pi5);

            PropertyInfo pi6=new PropertyInfo();
            pi6=new PropertyInfo();
            pi6.setType(decimal.class);
            pi6.setName("persons");
            pi6.setValue(persons);
            request.addProperty(pi6);

            SetEnvelope();
            //Create envelope
        }
    catch (Exception exception)
        {
        erorr= "error:"+exception.toString();
        }
    try
        {
            androidHttp.call(SOAP_ACTION, envelope);
            //Vector<String> result = null;
            //result = (Vector<String>) envelope.getResponse();
            String result = envelope.getResponse().toString();
            try { 
                id=Integer.parseInt(result); 
            } catch(NumberFormatException e) { 
                erorr=result;
            }
        }
    catch (Exception exception)
        {
        erorr= "error:"+exception.toString();
        }
    }
Note