[英]Android Login & Registration using Web service or ASP.NET denying a passed strings with KSoap2
I'm creating an Android application that will communicates between android and ASP.NET by using SOAP web service, and I'm using KSoap2 to do it. 我正在创建一个Android应用程序,该应用程序将通过使用SOAP Web服务在android和ASP.NET之间进行通信,而我正在使用KSoap2做到这一点。 And I am making is to register an account, which takes some user information, along with a " registration code " and then i use connect web service as used to connect to web-service to ASP .
我要做的是注册一个帐户,该帐户需要一些用户信息以及“ 注册码 ”,然后我使用连接网络服务来连接到ASP的网络服务。
My ASP.NET IIS is working properly. 我的ASP.NET IIS工作正常。
Ho to know that values are passing on web-services. 知道价值正在传递到Web服务上。 That possible to send value on .net and insert on sql server on android.
可能在.net上发送值并在android的sql服务器上插入。
registration code 登记码
public class Register extends Activity {
EditText edit_username;
EditText edit_displayName;
EditText edit_email;
EditText edit_password;
EditText edit_confirmPassword;
Button btn_register, btn_login;
Button btn_reset;
String user;
String disp, pass, email, conpass;
boolean RegisterStatus;
static boolean errored = false;
ProgressBar webservicePG;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
edit_username = (EditText) findViewById(R.id.edit_username);
edit_displayName = (EditText) findViewById(R.id.edit_name);
edit_email = (EditText) findViewById(R.id.edit_email);
edit_password = (EditText) findViewById(R.id.edit_password);
edit_confirmPassword = (EditText) findViewById(R.id.edit_confirmPassword);
btn_register = (Button) findViewById(R.id.btn_register);
btn_login = (Button) findViewById(R.id.reg_back_btn);
btn_reset = (Button) findViewById(R.id.btn_reset);
btn_reset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
edit_username.setText("");
edit_displayName.setText("");
edit_email.setText("");
edit_password.setText("");
edit_confirmPassword.setText("");
}
});
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Login.class);
startActivity(i);
}
});
btn_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (edit_username.getText().length() != 0
&& edit_username.getText().toString() != "") {
if (edit_displayName.getText().length() != 0
&& edit_displayName.getText().toString() != "") {
if (edit_email.getText().length() != 0
&& edit_email.getText().toString() != "") {
if (edit_password.getText().length() != 0
&& edit_password.getText().toString() != "") {
if (edit_confirmPassword.getText().length() != 0
&& edit_confirmPassword.getText()
.toString() != "") {
user = edit_username.getText().toString();
disp = edit_displayName.getText()
.toString();
pass = edit_password.getText().toString();
email = edit_email.getText().toString();
conpass = edit_confirmPassword.getText()
.toString();
// statusTV.setText("");
// Create instance for AsyncCallWS
AsyncCallWS task = new AsyncCallWS();
// Call execute
task.execute();
}
// If Password text control is empty
else {
// statusTV.setText("Please enter Password");
Toast.makeText(getApplicationContext(),
"Please enter Conform Password",
Toast.LENGTH_LONG).show();
edit_confirmPassword
.setError("Cannot Be Empty");
}
// If Username text control is empty
} else {
// statusTV.setText("Please enter Username");
Toast.makeText(getApplicationContext(),
"Please enter Password",
Toast.LENGTH_LONG).show();
edit_password.setError("Cannot Be Empty");
}
} else {
// statusTV.setText("Please enter Username");
Toast.makeText(getApplicationContext(),
"Please enter Email Address",
Toast.LENGTH_LONG).show();
edit_email.setError("Cannot Be Empty");
}
} else {
// statusTV.setText("Please enter Username");
Toast.makeText(getApplicationContext(),
"Please enter Dispalayname", Toast.LENGTH_LONG)
.show();
edit_displayName.setError("Cannot Be Empty");
}
} else {
// statusTV.setText("Please enter Username");
Toast.makeText(getApplicationContext(),
"Please enter Username", Toast.LENGTH_LONG).show();
edit_username.setError("Cannot Be Empty");
}
}
});
}
private class AsyncCallWS extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
// Call Web Method
RegisterStatus = WebService.invokeLoginWS(user, disp, email, pass,
conpass, "AuthenticateUser");
return null;
}
@Override
// Once WebService returns response
protected void onPostExecute(Void result) {
// Make Progress Bar invisible
webservicePG.setVisibility(View.INVISIBLE);
Intent intObj = new Intent(Register.this, Login.class);
// Error status is false
if (!errored) {
// Based on Boolean value returned from WebService
if (RegisterStatus) {
// Navigate to Home Screen
startActivity(intObj);
} else {
// Set Error message
Toast.makeText(getApplicationContext(),
"Register Failed, try again", Toast.LENGTH_LONG)
.show();
}
// Error status is true
} else {
// /statusTV.setText("Error occured in invoking webservice");
Toast.makeText(getApplicationContext(),
"Error occured in invoking webservice",
Toast.LENGTH_LONG).show();
}
// Re-initialize Error Status to False
errored = false;
}
@Override
// Make Progress Bar visible
protected void onPreExecute() {
webservicePG.setVisibility(View.VISIBLE);
}
@Override
protected void onProgressUpdate(Void... values) {
}
}
}
web service code 网络服务代码
public class WebService {
// Namespace of the Webservice - can be found in WSDL
private static String NAMESPACE = "http://tempuri.org/";
// Webservice URL - WSDL File location
private static String URL = "http://192.168.3.3/LoginCheck/Service.asmx";// Make
// sure
// you
// changed
// IP
// address
// SOAP Action URI again Namespace + Web method name
private static String SOAP_ACTION = "http://tempuri.org/";
public static boolean invokeLoginWS(String userName, String dispalyname,
String Email, String password, String conpassWord,
String webMethName) {
boolean loginStatus = false;
// Create request
SoapObject request = new SoapObject(NAMESPACE, webMethName);
// Property which holds input parameters
PropertyInfo unamePI = new PropertyInfo();
PropertyInfo passPI = new PropertyInfo();
// Set Username
unamePI.setName("username");
// Set Value
unamePI.setValue(userName);
// Set dataType
unamePI.setType(String.class);
// Add the property to request object
request.addProperty(unamePI);
passPI.setName("dispalyname");
// Set dataType
passPI.setValue(dispalyname);
// Set dataType
passPI.setType(String.class);// Set Password
passPI.setName("Email");
// Set dataType
passPI.setValue(Email);
// Set dataType
passPI.setType(String.class);
// Add the property to request object
request.addProperty(passPI);
// Set Password
passPI.setName("password");
// Set dataType
passPI.setValue(password);
// Set dataType
passPI.setType(String.class);
// Add the property to request object
request.addProperty(passPI);
// Set dataType
// Set Password
passPI.setName("conpassWord");
passPI.setValue(conpassWord);
// Set dataType
passPI.setType(String.class);
// Add the property to request object
request.addProperty(passPI);
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
// Invoke web service
androidHttpTransport.call(SOAP_ACTION + webMethName, envelope);
// Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
// Assign it to boolean variable variable
loginStatus = Boolean.parseBoolean(response.toString());
} catch (Exception e) {
// Assign Error Status true in static variable 'errored'
Login.errored = true;
e.printStackTrace();
}
// Return booleam to calling object
return loginStatus;
}
}
The requests sending from android to server can be listed in server log. 从android发送到服务器的请求可以在服务器日志中列出。 If you are not getting any error while sending request, it maybe recieved by the sever.
如果发送请求时没有收到任何错误,则服务器可能会收到该错误。 Otherwise check the internet connection and make sure to add the internet permission in the manifest, also refer the ksoap lib to java build path
否则,请检查Internet连接,并确保在清单中添加Internet许可,还请参考ksoap lib至Java构建路径
Check your WSDL file first and check your NAMESPACE = "http://tempuri.org/"
is correct or not ? 首先检查您的WSDL文件,并检查您的
NAMESPACE = "http://tempuri.org/"
是否正确? check your SOAP_ACTION = "http://tempuri.org/"
is correct or not ? 检查您的
SOAP_ACTION = "http://tempuri.org/"
是否正确? In your code,comments are available before the declaration of NAMESPACE and SOAP_ACTION please follow the comments and WSDL file for your NAMESPACE and SOAP_ACTION. 在您的代码中,在声明NAMESPACE和SOAP_ACTION之前可以进行注释,请遵循注释和WSDL文件中的NAMESPACE和SOAP_ACTION。
SOAP Action = URI again Namespace + Web method name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.