如何利用基于SOAP的Web服务的Andr​​oid [英] how to use soap based web service android

查看:114
本文介绍了如何利用基于SOAP的Web服务的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android中使用基于SOAP的Web服务,但我不知道如何使用基于SOAP的Web服务的概念。我previously做XML解析简单的XML Web服务,但不知道基于SOAP的。你能告诉我如何在Android中使用基于SOAP的Web服务...

I want to use a SOAP-based web service in Android, but I don't know the concept of how to use SOAP-based web services. I previously have done XML parsing for simple XML web services, but don't know about SOAP-based ones. Can you tell me how to use SOAP-based web services in Android...

推荐答案

试试这个,这code是使用KSOAP登录用户

Try this, This code is for login-user using Ksoap

public class Login extends Activity {
    /** Called when the activity is first created. */

    private static final String SOAP_ACTION = "http://tempuri.org/LoginUser";
    private static final String METHOD_NAME = "LoginUser";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://"
    private static final String TAG = "HELLO"

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button signin = (Button) findViewById(R.id.regsubmitbtn);
        signin.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                new StartLoginAsyncTask(yourclass.this).execute();
            }
        });
    }

    private class LoginTask extends AsyncTask<Void, Void, Boolean> {
        private final ProgressDialog dialog =
            new ProgressDialog(YourClass.this);

        protected void onPreExecute() {
            this.dialog.setMessage("Logging in.........");
            this.dialog.show();
        }

        protected Boolean doInBackground(final Void unused) {
            return Main.this.login(); //don't interact with the ui!
        }

        protected void onPostExecute(final Boolean result) {
            if (this.dialog.isShowing()) {
                this.dialog.dismiss();
            }
            if (result.booleanValue()) {
                //also show register success dialog
            }
        }
    }

    private String doLogin() {
        EditText etxt_user = (EditText)findViewById(R.id.emaileditlog);
        String email_id = etxt_user.getText().toString();
        EditText etxt_password = (EditText)findViewById(R.id.pwdeditlog);
        String password = etxt_password.getText().toString();
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("email", email);
        request.addProperty("password", password);

        SoapSerializationEnvelope soapEnvelope =
            new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(request);
        HttpTransportSE aht = new HttpTransportSE(URL);

        Pattern EMAIL_ADDRESS_PATTERN =
            Pattern.compile("[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
                            "\\@" +
                            "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
                            "(" +
                            "\\." +
                            "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
                            ")+");
        Matcher matcher = EMAIL_ADDRESS_PATTERN.matcher(email_id);
        if (matcher.matches()) {
            Log.v(TAG, "Your email id is valid ="+email_id);
            //  System.out.println("Your email id is valid ="+email);
        } else {
            //  System.out.println("enter valid email id");
            Log.v(TAG, "enter valid email id" );
        }
        if (password != null) {
            if (email_id.equalsIgnoreCase("") || password.equalsIgnoreCase("")) {
                System.out.println("Fields should not be EMPTY");
            }
        }
        SoapObject request = new SoapObject(NAMESPACE_LOGIN, METHOD_NAME_LOGIN);
        request.addProperty("email", email_id);
        request.addProperty("pwd", password);

        SoapSerializationEnvelope soapEnvelope =
            new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(request);
        HttpTransportSE aht = new HttpTransportSE(URL_LOGIN);

        try {
            aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 
            aht.call(SOAP_ACTION_LOGIN, soapEnvelope);

            SoapObject resultsRequestSOAP = (SoapObject) soapEnvelope.bodyIn;
            Log.v("TAG", String.valueOf(resultsRequestSOAP));

            Object response=(Object)soapEnvelope.getResponse();
            temp=response.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return temp;
    }
}

这篇关于如何利用基于SOAP的Web服务的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆