java.net.sockettimeoutexception连接超时ksoap2

时间:2015-03-16 08:06:35

标签: android web-services ksoap2

我正在开发一个应用程序,我正在使用Soap webservices,我在我的应用程序中开始这一天的问题,我在互联网上搜索解决方案并尝试所有可能的解决方案,但它不是工作,现在这个问题对我来说非常烦人,请帮助n提前感谢帮助。另外我可以分享我的活动请检查这是我的代码错误或问题是在服务器端..

我的活动:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setLogo(R.drawable.ic_launcher);
    actionBar.setDisplayUseLogoEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                .permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    // errorMsg = (TextView) findViewById(R.id.login_error);

    et_username = (EditText) findViewById(R.id.editText_Mobile);
    et_password = (EditText) this.findViewById(R.id.editText_password);

    btn_signin = (Button) findViewById(R.id.btn_signin);
    btn_create_login = (Button) findViewById(R.id.btn_create_login);
    tv_forgotpass = (TextView) findViewById(R.id.tv_forgotpass);
    tv_login_num = (TextView) findViewById(R.id.tv_login_num);

    prgDialog = new ProgressDialog(this);
    // Set Progress Dialog Text
    prgDialog.setMessage("Please wait...");
    // Set Cancelable as False
    prgDialog.setCancelable(false);

    pDialog = new ProgressDialog(MainActivity.this);

    btn_create_login.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(MainActivity.this,
                    RegisterActivity.class);
            startActivity(intent);
            et_username.setText("");
            et_password.setText("");
        }
    });

    btn_signin.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            loginAction();
        }
    });


}

private void loginAction() {
    request = new SoapObject(NAMESPACE, METHOD_NAME);
    Log.d("SelfCare", "NAMESPACE= " + NAMESPACE);
    Log.d("SelfCare", "METHOD_NAME= " + METHOD_NAME);

    // EditText userName = (EditText) findViewById(R.id.editText1);
    username = et_username.getText().toString();
    // EditText userPassword = (EditText) findViewById(R.id.editText2);
    String user_Password = et_password.getText().toString();
    String apptypecode = "TXDIY0006";

    Log.d("SelfCare", "user_Name= " + username);
    Log.d("SelfCare", "password= " + user_Password);

    /*
     * request.addProperty("username", user_Name);
     * request.addProperty("password", user_Password);
     * request.addProperty("apptypecode", apptypecode);
     */

    // Pass value for userName variable of the web service
    if (username.trim().equals("")) {
        alertDialog("Please Enter Username");
        et_username.requestFocus();
    } else if (user_Password.equals("")) {
        alertDialog("Please Enter Your Password");
        et_password.requestFocus();
    } else {
        PropertyInfo unameProp = new PropertyInfo();
        unameProp.setName("username");// Define the variable name in the web
                                        // service method
        unameProp.setValue(username);// set value for userName variable
        unameProp.setType(String.class);// Define the type of the variable
        request.addProperty(unameProp);// Pass properties to the variable

        // Pass value for Password variable of the web service
        PropertyInfo passwordProp = new PropertyInfo();
        passwordProp.setName("password");
        passwordProp.setValue(user_Password);
        passwordProp.setType(String.class);
        request.addProperty(passwordProp);

        PropertyInfo apptypecodes = new PropertyInfo();
        apptypecodes.setName("apptypecode");
        apptypecodes.setValue(apptypecode);
        apptypecodes.setType(String.class);
        request.addProperty(apptypecodes);

        new AsyncCallWS().execute();
    }

}

private class AsyncCallWS extends AsyncTask<String, Void, Void> {
    @Override
    protected Void doInBackground(String... params) {

        try {

            envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            envelope.dotNet = true;
            Log.d("SelfCare", "request= " + request);
            // androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport = new HttpTransportSE(URL, 60000);

            Log.d("SelfCare", "androidHttpTransport= "
                    + androidHttpTransport);

            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            Log.d("SelfCare", "response= " + response);
            /*
             * Toast.makeText(getApplicationContext(), "Response= " +
             * response, Toast.LENGTH_LONG).show();
             */
            String jsonResponse = "";
            jsonResponse = response.toString();

            // A JSONTokener is needed in order to use JSONObject correctly
            JSONTokener jsonTokener = new JSONTokener(jsonResponse);
            // Pass a JSONTokener to the JSONObject constructor
            JSONObject jsonObj = new JSONObject(jsonTokener);
            JSONArray data = jsonObj.getJSONArray("data");

            if (data != null) {

                // looping through All nodes
                for (int i = 0; i < data.length(); i++) {
                    JSONObject c = data.getJSONObject(i);
                    message = c.getString("message");
                    sessionid = c.getInt("sessionid");
                    saleid = c.getInt("saleid");
                    name = c.getString("name");
                    email = c.getString("email");
                    defaultmsisdn = c.getString("defaultmsisdn");
                    associatedArray = c.getString("AssociatedArray");

                    AssociatedArray.add(associatedArray);

                    Log.d("SelfCare farhan aarray", "AssociatedArray= "
                            + AssociatedArray);



                }

                /*
                 * Toast.makeText(getBaseContext(), "Success",
                 * Toast.LENGTH_LONG).show();
                 */

            } else {
                /*
                 * Toast.makeText(getBaseContext(), "Error",
                 * Toast.LENGTH_LONG) .show();
                 */}

            /*
             * TextView results = (TextView) findViewById(R.id.login_error);
             * results.setText(response.toString());
             */

        } catch (Exception e) {
            // alertDialog(e.toString());
            /*
             * Toast.makeText(getApplicationContext(), e.getMessage(),
             * Toast.LENGTH_LONG).show();
             */
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // Log.i(TAG, "onPostExecute");
        // tv.setText(fahren + "° F");

        pDialog.dismiss();

        if (message != null) {

            if (message.equalsIgnoreCase("Login Successful.")) {
                if (defaultmsisdn.equalsIgnoreCase("null") && saleid == 0) {
                    et_username.setText("");
                    et_password.setText("");
                    Intent intent = new Intent(getApplicationContext(),
                            AssociateMsisdn.class);
                    intent.putExtra("username", username);
                    intent.putExtra("sessionid", sessionid);
                    intent.putExtra("name", name);
                    intent.putExtra("email", email);
                    intent.putExtra("AssociatedArray", associatedArray);
                    startActivity(intent);
                    // alertDialog("Open the Associate MSISDN Class.");
                } else {
                    et_username.setText("");
                    et_password.setText("");
                    Intent intent = new Intent(getApplicationContext(),
                            MainMenu.class);
                    intent.putExtra("name", name);
                    intent.putExtra("username", username);
                    intent.putExtra("defaultmsisdn", defaultmsisdn);
                    intent.putExtra("sessionid", sessionid);
                    intent.putExtra("saleid", saleid);
                    intent.putExtra("email", email);
                    intent.putExtra("AssociatedArray", associatedArray);

                    Log.d("SelfCare farhan aarray put", "AssociatedArray= "
                            + AssociatedArray);
                    // intent.putStringArrayListExtra("AssociatedArray",
                    // AssociatedArray);

                    /*
                     * intent.putExtra("associatedmsisdn",
                     * associatedmsisdn);
                     * intent.putExtra("associatedsaleid",
                     * associatedsaleid);
                     * intent.putExtra("associatedmsisdn1",
                     * associatedmsisdn1);
                     * intent.putExtra("associatedsaleid1",
                     * associatedsaleid1);
                     */

                    startActivity(intent);
                }
            } else {
                alertDialog(message);
                // Toast.makeText(getApplicationContext(), "" +message ,
                // Toast.LENGTH_LONG).show();
            }
        } else {
            alertDialog(getResources().getString(R.string.server_error));
        }
    }

    @Override
    protected void onPreExecute() {

        pDialog.setMessage("Logging in ...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        // Log.i(TAG, "onProgressUpdate");
    }

}

0 个答案:

没有答案