-1

I want to create SOAP request programatically having following structure by using the ksoap2-android-assembly-2.5.8-jar-with-dependencies.jar :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:con="http://www.google.com/Consumer/">
   <soapenv:Header>
      <con:RequestHeader>
         <!--Optional:-->
         <serviceId></serviceId>
         <serviceCode>CUSTREG</serviceCode>
         <phaseCode>MOBREG</phaseCode>
         <subTransactionCode>MOBREG</subTransactionCode>
         <interactionCode>LOGIN</interactionCode>
         <!--Optional:-->
         <bearer></bearer>
         <!--Optional:-->
         <clientRefId></clientRefId>
      </con:RequestHeader>
   </soapenv:Header>
   <soapenv:Body>
      <con:Login>
         <LoginRequest>
            <uniqueId>+911234567890</uniqueId>
            <password>123456</password>
            <!--Optional:-->
            <uuid></uuid>

         </LoginRequest>
      </con:Login>
   </soapenv:Body>
</soapenv:Envelope>

Thanks in Advance.

Prateek
  • 306
  • 4
  • 17

1 Answers1

0
public class GetLogin extends AsyncTask<String, Void, String>
    {
        ProgressDialog pd ;
        public String WSDL_TARGET_NAMESPACE = "http://tempuri.org/"; // initialise it with your NAMESPACE
        private Context _context;
        public String URL = "";  // initialise it with your URL
        public GetLogin(Context c)
        {
            _context = c;
        }

        protected void onPreExecute()
        {
            super.onPreExecute();
            pd = new ProgressDialog(_context);
            pd.setTitle("Authenticating");
            pd.setMessage("Please wait...");
            pd.setCancelable(true);
            pd.setIndeterminate(true);
            pd.show();
        }

        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            if (params[0].trim().equals("")) {
                return "";
            }

            SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, params[0].trim());

            request.addProperty("uniqueId",params[1]);
            request.addProperty("password",params[2]);   // uniqueId and password are method parameters. You should use exactly the way it is.

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

            envelope.dotNet = true;

            envelope.setOutputSoapObject(request);


            HttpTransportSE httpTransport = new HttpTransportSE(URL);

            try
            {
                httpTransport.call(WSDL_TARGET_NAMESPACE + params[0].trim(), envelope);

                SoapPrimitive response = (SoapPrimitive) envelope.getResponse();

                return response.toString();
            }

            catch (Exception e)
            {
                if (pd.isShowing())
                    pd.dismiss();

            }

        }


        protected void onPostExecute(String str)
        {
            super.onPostExecute(str);

                if (pd.isShowing())
                    pd.dismiss();
            // str has the retrieved information from the web service.
        }

Call it from the activity like

 new GetLogin(yourActivity.this).execute("MethodName", "Parameter1", "Parameter2");
Aniruddha
  • 4,477
  • 2
  • 21
  • 39