TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sourabh Raorane
NA
1
928
unable to login through android using dot net web services
Sep 13 2015 2:54 AM
Hello
I am new to android , i am developing android application which has log in through dot net web services but my code is not working out.
Here is my code
my main activity it is named as CheckDNLoginActivity.java
public class CheckDNLoginActivity extends Activity {
//Set Error Status
static boolean errored = false;
Button b;
TextView statusTV;
EditText userNameET , passWordET;
ProgressBar webservicePG;
String editTextUsername;
boolean loginStatus;
String editTextPassword;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Name Text control
userNameET = (EditText) findViewById(R.id.editText1);
passWordET = (EditText) findViewById(R.id.editText2);
//Display Text control
statusTV = (TextView) findViewById(R.id.tv_result);
//Button to trigger web service invocation
b = (Button) findViewById(R.id.button1);
//Display progress bar until web service invocation completes
webservicePG = (ProgressBar) findViewById(R.id.progressBar1);
//Button Click Listener
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Check if text controls are not empty
if (userNameET.getText().length() != 0 && userNameET.getText().toString() != "") {
if(passWordET.getText().length() != 0 && passWordET.getText().toString() != ""){
editTextUsername = userNameET.getText().toString();
editTextPassword = passWordET.getText().toString();
statusTV.setText("");
//Create instance for AsyncCallWS
PostDataAsyncTask task = new PostDataAsyncTask();
//Call execute
task.execute();
}
//If Password text control is empty
else{
statusTV.setText("Please enter Password");
}
//If Username text control is empty
} else {
statusTV.setText("Please enter Username");
}
}
});
}
private class PostDataAsyncTask extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
//Call Web Method
loginStatus = WebService.invokeLoginWS(editTextUsername,editTextPassword,"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(CheckDNLoginActivity.this,HomeActivity.class);
//Error status is false
if(!errored){
//Based on Boolean value returned from WebService
if(loginStatus){
//Navigate to Home Screen
startActivity(intObj);
}else{
//Set Error message
statusTV.setText("Login Failed, try again");
}
//Error status is true
}else{
statusTV.setText("Error occured in invoking webservice");
}
//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) {
}
}
}
HERE IS MY WEB SERVICES CODE BELOW
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://198.7.57.72:8080/PropertytaxWB.asmx";//Make sure you changed IP address
//SOAP Action URI again Namespace + Web method name
private static String SOAP_ACTION = "http://tempuri.org/WS_Get_UserProfile";
public static boolean invokeLoginWS(String userName,String passWord, 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("User_Name");
// Set Value
unamePI.setValue(userName);
// Set dataType
unamePI.setType(String.class);
// Add the property to request object
request.addProperty(unamePI);
//Set Password
passPI.setName("User_Password");
//Set dataType
passPI.setValue(passWord);
//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'
CheckDNLoginActivity.errored = true;
e.printStackTrace();
}
//Return booleam to calling object
return loginStatus;
}
}
Reply
Answers (
0
)
sql db Connectivity
Drag and drop a selected picture in android