晚上好,我正在尝试制作代码,这样我就可以将我的Android应用程序与我的Web服务连接,最终到达MS数据库。我试过异步过程,但我没有成功。
这是我的代码:
private Button btnLogin;
private EditText txtUsername;
private EditText txtPassword;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
txtUsername = (EditText) findViewById(R.id.ePersonName);
txtPassword = (EditText) findViewById(R.id.ePassword);
btnLogin = (Button) findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LoginWSsql login = new LoginWSsql();
login.execute();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login_activity, menu);
return true;
}
private class LoginWSsql extends AsyncTask<String,Integer,Boolean>
{
protected Boolean doInBackground(String... params) {
boolean resul = true;
final String NAMESPACE = "http://tempuri.org/";
final String URL="http://192.168.1.104:9090/PruebaAndroid.asmx";
final String METHOD_NAME = "PruebaAndroid";
final String SOAP_ACTION = "http://tempuri.org/PruebaAndroid";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("", txtUsername.getText().toString());
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE transporte = new HttpTransportSE(URL);
try
{
transporte.call(SOAP_ACTION, envelope);
SoapPrimitive resultado_xml =(SoapPrimitive)envelope.getResponse();
String res = resultado_xml.toString();
if(res.equals("hola madlito"))
{
resul = false;
}
}
catch (Exception e)
{
resul = false;
}
return resul;
}
protected void onPostExecute(Boolean result) {
if (result)
Toast.makeText(getBaseContext(), "conectado",Toast.LENGTH_SHORT).show();
else
Toast.makeText(getBaseContext(), "Falla",Toast.LENGTH_SHORT).show();
}
}
}
问题在于,当我点击按钮时,程序会立即粉碎并向我发送此消息:
不幸的是,SecurityAPP已停止。
有人可以帮助我!!!!!