How to call web service to achieve login system in Android?

夙愿已清 提交于 2020-01-03 05:09:08

问题


i have a xml project. this is the Login sample code

http://10.99.99.99:8087/item/services/ItemService

   <soapenv:Header/>
   <soapenv:Body>
      <ser:userLogin>
         <!--Optional:-->
         <arg0>admin</arg0>
         <!--Optional:-->
         <arg1>admin</arg1>
      </ser:userLogin>
   </soapenv:Body>
</soapenv:Envelope>

If Succeed

<soap:Body>
      <ns2:userLoginResponse xmlns:ns2="http://services.ws.item/">
         <return>
            <result>1</result>
            <msg>Login Succeed</msg>
         </return>
      </ns2:userLoginResponse>
   </soap:Body>
</soap:Envelope>

If Not Succeed

   <soap:Body>
      <ns2:userLoginResponse xmlns:ns2="http://services.ws.item/">
         <return>
            <result>-1</result>
            <msg>Login failed</msg>
         </return>
      </ns2:userLoginResponse>
   </soap:Body>
</soap:Envelope>

the service will connect to MySQL server.

i change the test code, but it still cannot run, and i am so sure the wsdl is work. the logcat shows a lot of error.

    public class CheckLoginActivity extends Activity {


        private static final String SOAP_ACTION = "http://services.ws.item/userLogin";
        private static final String METHOD_NAME = "userLogin";
        private static final String NAMESPACE = "http://services.ws.item/";
        private static final String URL = "http://10.99.99.99:8087/item/services/ItemService?wsdl";
        private TextView tv;
        private String response;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            tv= (TextView)findViewById(R.id.tv1);

            myAsyncTask myRequest = new myAsyncTask();
            myRequest.execute();

        }

        private class myAsyncTask extends AsyncTask<Void, Void, Void>    {


            @Override
            protected void onPostExecute(Void result) {
                super.onPostExecute(result);
//              tv.setText(response);
            }

            @Override
            protected void onPreExecute() {
                super.onPreExecute();       
            }

            @Override
            protected Void doInBackground(Void... arg0) {

                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                request.addProperty("arg0", "admin"); 
                request.addProperty("arg1", "admin"); 

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

                HttpTransportSE httpTransport = new HttpTransportSE(URL);

                httpTransport.debug = true;  
                try {
                    httpTransport.call(SOAP_ACTION, envelope);
                } catch (HttpResponseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } //send request
                SoapPrimitive result;
                try {
                    result = (SoapPrimitive) envelope.getResponse();
                    Log.d("App",""+result.toString());
                    response = result.toString();
                } catch (SoapFault e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                return null;
            }   
        }   
    }

来源:https://stackoverflow.com/questions/31779473/how-to-call-web-service-to-achieve-login-system-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!