-2

我的 MainActivity.java

package com.test11;
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.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity

{


private static String SOAP_ACTION1 = "http://tempuri.org/Service/ValidateUser";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME1 = "ValidateUser";
private static String URL = ".....";

Button button1;
EditText editText1,editText2;


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

    button1 = (Button)findViewById(R.id.button1);


    button1.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
        editText1 = (EditText)findViewById(R.id.editText1);
        editText2 = (EditText)findViewById(R.id.editText2);
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);       

        request.addProperty("parameters",editText2.getText().toString());

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);



        envelope.setOutputSoapObject(request);
        envelope.dotNet = true;

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        androidHttpTransport.debug = true;


        try {



            androidHttpTransport.call(SOAP_ACTION1, envelope);

            SoapObject result = (SoapObject)envelope.bodyIn;




            if(result != null)
            {

                editText1.setText(result.getProperty(0).toString());
            }
            else
            {

                Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) 
        {

            e.printStackTrace();
        }
        }


    });    

}




}

我尝试制作一个 android 应用程序,它提供用户名并将其与 Web 服务连接,因此如果用户名存在或不存在,它将返回真或假。我使用 ksoap2 在 eclipse 中运行它并且总是返回 false ......即使使用现有的用户名。

4

1 回答 1

0

也许您的问题不在您的 android 代码中,而在 web 服务中。尝试直接在您的网络服务中测试它

于 2013-07-15T14:34:48.900 回答