Skip to content Skip to sidebar Skip to footer

How To Use Soap Based Web Service Android

I want to use a SOAP-based web service in Android, but I don't know the concept of how to use SOAP-based web services. I previously have done XML parsing for simple XML web service

Solution 1:

Try this, This code is for login-user using Ksoap

publicclassLoginextendsActivity {
    /** Called when the activity is first created. */privatestaticfinalStringSOAP_ACTION="http://tempuri.org/LoginUser";
    privatestaticfinalStringMETHOD_NAME="LoginUser";
    privatestaticfinalStringNAMESPACE="http://tempuri.org/";
    privatestaticfinalStringURL="http://"privatestaticfinalStringTAG="HELLO"@OverridepublicvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Buttonsignin= (Button) findViewById(R.id.regsubmitbtn);
        signin.setOnClickListener(newOnClickListener() {
            publicvoidonClick(View v) {
                newStartLoginAsyncTask(yourclass.this).execute();
            }
        });
    }

    privateclassLoginTaskextendsAsyncTask<Void, Void, Boolean> {
        privatefinalProgressDialogdialog=newProgressDialog(YourClass.this);

        protectedvoidonPreExecute() {
            this.dialog.setMessage("Logging in.........");
            this.dialog.show();
        }

        protected Boolean doInBackground(final Void unused) {
            return Main.this.login(); //don't interact with the ui!
        }

        protectedvoidonPostExecute(final Boolean result) {
            if (this.dialog.isShowing()) {
                this.dialog.dismiss();
            }
            if (result.booleanValue()) {
                //also show register success dialog
            }
        }
    }

    private String doLogin() {
        EditTextetxt_user= (EditText)findViewById(R.id.emaileditlog);
        Stringemail_id= etxt_user.getText().toString();
        EditTextetxt_password= (EditText)findViewById(R.id.pwdeditlog);
        Stringpassword= etxt_password.getText().toString();
        SoapObjectrequest=newSoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("email", email);
        request.addProperty("password", password);

        SoapSerializationEnvelopesoapEnvelope=newSoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(request);
        HttpTransportSEaht=newHttpTransportSE(URL);

        PatternEMAIL_ADDRESS_PATTERN=
            Pattern.compile("[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
                            "\\@" +
                            "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
                            "(" +
                            "\\." +
                            "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
                            ")+");
        Matchermatcher= EMAIL_ADDRESS_PATTERN.matcher(email_id);
        if (matcher.matches()) {
            Log.v(TAG, "Your email id is valid ="+email_id);
            //  System.out.println("Your email id is valid ="+email);
        } else {
            //  System.out.println("enter valid email id");
            Log.v(TAG, "enter valid email id" );
        }
        if (password != null) {
            if (email_id.equalsIgnoreCase("") || password.equalsIgnoreCase("")) {
                System.out.println("Fields should not be EMPTY");
            }
        }
        SoapObjectrequest=newSoapObject(NAMESPACE_LOGIN, METHOD_NAME_LOGIN);
        request.addProperty("email", email_id);
        request.addProperty("pwd", password);

        SoapSerializationEnvelopesoapEnvelope=newSoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(request);
        HttpTransportSEaht=newHttpTransportSE(URL_LOGIN);

        try {
            aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 
            aht.call(SOAP_ACTION_LOGIN, soapEnvelope);

            SoapObjectresultsRequestSOAP= (SoapObject) soapEnvelope.bodyIn;
            Log.v("TAG", String.valueOf(resultsRequestSOAP));

            Object response=(Object)soapEnvelope.getResponse();
            temp=response.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return temp;
    }
}

Solution 2:

You should download and try out ksoap2 for Android.

Solution 3:

You must do a thorugh research before asking a question. It is a simple problem which can be solved using google.

Anway, use these links

http://tknight.org/sdn/show/23160

http://www.android10.org/index.php/articleslibraries/167-using-ksoap2-for-android-soap-web-service

http://android.amberfog.com/?p=45

Also, use ksoap2 library from http://code.google.com/p/ksoap2-android/source/browse/m2-repo/com/google/code/ksoap2-android/ksoap2-android-assembly/2.5.7/ksoap2-android-assembly-2.5.7-jar-with-dependencies.jar. Click on view raw file to download the jar

Post a Comment for "How To Use Soap Based Web Service Android"