Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a PHP Webservice from Android using KSOAP2?

Tags:

android

can anybody suggest "How to call a PHP Webservice from Android using KSOAP2?"

like image 271
Subrat Avatar asked Sep 16 '10 19:09

Subrat


1 Answers

sample code provided now you try yourself :)

private  final String SOAP_ACTION = "urn:abc#login";
      private  final String METHOD_NAME = "UserLogin";
      private  final String NAMESPACE = "urn:abcwsdl";
      private  final String URL =  "http://abc.com/service/server.php";

public void login()
{
SoapObject userRequest=new SoapObject(NAMESPACE, METHOD_NAME);
            userRequest.addProperty("email", email); // login-account
            userRequest.addProperty("password", password); // login-password

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("UserLogin", userRequest); // login-account


            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.bodyOut = request;


            HttpTransportAndroid androidHttpTransport = new HttpTransportAndroid(URL);



            try {




              Object result=envelope.getResult();

                  res=new DalLogin();
                SoapObject resp=(SoapObject) result;
                if(((SoapObject)result).getProperty("result").equals("error"))
                {

                    res.setError_string("error");
                    res.setResult(resp.getProperty("response").toString());

                }else
                {
                res.setError_string(null);
                res.setUser_id(resp.getProperty("user_id").toString());
                res.setSession_id(resp.getProperty("session_id").toString());



                }


            } catch (Exception aE) {
              aE.printStackTrace();
            }

}
like image 109
UMAR-MOBITSOLUTIONS Avatar answered Nov 05 '22 02:11

UMAR-MOBITSOLUTIONS