簡體   English   中英

Web服務響應失敗Soap 2

[英]web service response fails Soap 2

package bt.Mobile.abc;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

public class HelloAndroidActivity extends Activity {
    private static final String APP_TAG = "BT Android";

    // TO VALIDATE THE LOGIN
    private static final String SOAP_ACTION = "http://SmartApp.boothtracker.com/ValidateLogin";
    private static final String METHOD_NAME = "ValidateLogin";
    private static final String NAMESPACE = "*****.com/";
    private static final String URL = "*****.asmx";

    TextView tvUserName;
    TextView tvPassword;
    TextView tvStatus;
    ProgressBar progressBar1;

    /** SelectedBooth used to store the Selected Booths **/
    public String SelectedBooth;

    public String getSelectedBooth() {
        return SelectedBooth;
    }

    public void setSelectedBooth(String SelectedBooth) {
        this.SelectedBooth = SelectedBooth;
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {           
        super.onCreate(savedInstanceState);

        new eula.OnEulaAgreedTo() {

            public void onEulaAgreedTo() {
                // TODO Auto-generated method stub

            }
        };

        // VALIDATE USER LOGIN
        try
        {
            setContentView(R.layout.main);

            // INITIALIZE CONTROLS USED IN FORM
            tvUserName=(TextView)findViewById(R.id.editText1);
            tvPassword=(TextView)findViewById(R.id.editText2);
            tvStatus=(TextView)findViewById(R.id.txtStatus);

            progressBar1 = (ProgressBar)findViewById(R.id.progressBar1);
            progressBar1.setVisibility(View.GONE);

            Button b = (Button)findViewById(R.id.btnSignIn);            
            b.setOnClickListener(new View.OnClickListener(){
                public void onClick(View arg0){ 

                    progressBar1.setVisibility(View.VISIBLE);
                    tvStatus.setText("Processing...");

                    try {
                        // INVOKE THE WS TO GET THE LOGIN VALIDATED 
                        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);                       
                        request.addProperty("UserName", tvUserName.getText().toString());`enter code here`
                        request.addProperty("Password", tvPassword.getText().toString());                   
                        Toast.makeText(getApplicationContext(), ("Connecting"), Toast.LENGTH_LONG).show();
                        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);                     
                        envelope.dotNet=true;
                        envelope.setOutputSoapObject(request);
                        Toast.makeText(getApplicationContext(), (URL), Toast.LENGTH_LONG).show();
                        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                        androidHttpTransport.call(SOAP_ACTION, envelope);                   
                        Toast.makeText(getApplicationContext(), ("Sending"), Toast.LENGTH_LONG).show();
                        Object result = (Object)envelope.getResponse();

                        String strResult = result.toString();

                        progressBar1.setVisibility(View.GONE);

                        if  (strResult.equals("True"))
                        {
                            //LOGIN WAS SUCESSFULL - PROCED TO NEXT PAGE
                            tvStatus.setText("Login Successfull, Please Wait...");
                            tvPassword.setText("");
                            Intent i = new Intent(HelloAndroidActivity.this, newfile.class);
                            startActivity(i);
                            finish();
                        }
                        else
                        {
                            // LOGIN FAILED TO AUTHENTICATE
                            Toast.makeText(getApplicationContext(), ("Invalid Username and Password"), Toast.LENGTH_LONG).show();
                            tvStatus.setText("Invalid username & password");
                            tvPassword.setText("");
                        }

                    } catch (Exception e) {
                        // LOGIN FAILED; NOTIFY THE USER AND WAIT
                        Toast.makeText(getApplicationContext(), (e.getMessage()), Toast.LENGTH_LONG).show();
                        tvStatus.setText("Connection Failure");
                        tvStatus.setText(e.getMessage());
                        tvPassword.setText("");
                    }
                }
            });
        }
        catch (Exception e)
        {
            Log.e(APP_TAG, Log.getStackTraceString(e));
        }
    }
}

我是Android的新手,我創建了一個小應用程序並調用了Web方法。 它始終可以正常工作,但是突然停止工作,無法連接到WS。 我正在使用KSOAP2。 我能夠通過瀏覽器訪問WS。 我沒有對代碼進行任何更改。在交付時,它運行正常,一切正常。

版本-GingerBread,使用Eclipse,WS是asmx。 我正在使用2.6.5 jar的KOSAP2 ..請幫助我非常關鍵

代替

 Object result = (Object)envelope.getResponse();

嘗試使用

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM