我是android的新手。我正在尝试通过异步任务中的ksoap使用.net webservise。但是应用程序崩溃了。我不知道问题出在哪里。这是我的代码......请帮助我......
public class LoginActivity extends Activity {
private String METHOD_NAME = "AuthenticateUser"; // our webservice method name
private String NAMESPACE = "http://tempuri.org/";
private String SOAP_ACTION = "http://tempuri.org/AuthenticateUser";
// private String SOAP_ACTION = "http://LocationBasedTaxiServices/UserWebServices.asmx/RegisterUser"; // NAMESPACE + method name
private static final String URL = "http://192.168.0.45/LocationBasedTaxiServices/UserWebServices.asmx?WSDL"; // you
//////////////////////getting email amd password from R file////////////////
private EditText login_email;
private EditText login_password;
private String result;
private Button loginbtn;
private TextView registerTextView;
String user_id;
String password;
String authentication;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
loginbtn=(Button)findViewById(R.id.btnLogin);
login_email=(EditText)findViewById(R.id.l_e);
login_password=(EditText)findViewById(R.id.l_p);
loginbtn.setOnClickListener(new View.OnClickListener() {
// SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
public void onClick(View v) {
user_id=login_email.getText().toString();
password=login_password.getText().toString();
new asynLogin().execute();
}
});
registerTextView =(TextView)findViewById(R.id.link_to_register);
registerTextView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), Register.class);
startActivity(i);
}
});
}
private class asynLogin extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(LoginActivity.this);
protected void onPreExecute() {
this.dialog.setMessage("Logging in...");
this.dialog.show();
}
protected Void doInBackground(final Void... unused) {
// authentication = doLogin(user_id, password);
authentication = doLogin(user_id,password);
return null; // don't interact with the ui!
}
protected void onPostExecute(Void result) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
if (authentication.equals(true)) {
Intent i=new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
finish();
} else {
Toast.makeText(getApplicationContext(), "User Name Does Not exist", Toast.LENGTH_LONG).show();
}
}
private String doLogin(String user_id, String password) {
SoapPrimitive resultstring = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("email", user_id);
request.addProperty("password", password);
SoapSerializationEnvelope soapenvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapenvelope.dotNet = true;
soapenvelope.setOutputSoapObject(request);
HttpTransportSE httptransport = new HttpTransportSE(URL);
httptransport.debug = true;
try {
httptransport.call(SOAP_ACTION, soapenvelope);
resultstring = (SoapPrimitive) soapenvelope.getResponse();
result=resultstring.toString();
login_email.setText(result);
Log.i("myLogin", resultstring.toString());
System.out.println(resultstring);
} catch (SocketException ex) {
login_email.setText(ex.getMessage());
Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
ex.printStackTrace();
} catch (Exception e) {
Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage());
e.printStackTrace();
}
// return resultstring+"";
return result;
}
}
}
请帮助我。提前致谢。面对从一个活动到另一个活动的问题,而 web 服务的响应与我想要的完全一样......