我的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服务连接,因此如果用户名存在与否,它将返回true或false。 我使用ksoap2在eclipse中运行它,并且总是返回false ...即使使用现有的用户名。
答案 0 :(得分:0)
也许你的问题不在你的android代码中,而是在webservice中。尝试直接在您的网络服务中进行测试