ksoap-Accessing web service with BlackBerry

Check weather given username and password are correct by connecting to remote server.returns true or false according to server response

Add ksoap jar module to your project

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

public boolean createSoap(String username,String password)
{
    boolean ans=false;
    SoapObject request = new SoapObject("http://tempuri.org/","isValidUser");
     request.addProperty("Username",username);
     request.addProperty("Password",password);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.bodyOut = request;
    envelope.dotNet = true;
    HttpTransport ht = new HttpTransport("http://164.49.254.143:8080/Service.asmx");
    ht.debug = true;
    try {
        ht.call("http://tempuri.org/isValidUser", envelope);     
        if((envelope.getResponse().toString()).equals("true"))
        {
            return true;   
        }
    }
    catch (XmlPullParserException ex)
    {
        Dialog.alert("ex1 "+ex.toString() );
        ex.printStackTrace();
    } catch (IOException ex) {
        Dialog.alert("ex2 " +ex.toString());
        ex.printStackTrace();
    } catch (Exception ex) {
        Dialog.alert("ex3 " + ex.toString());
    }
    return false;
}

No comments:

Post a Comment

Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release

  Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...