I have created a WCF services to connect my android app with my SQL database on online site , first of all I can test the service on my local machine but on the server I can't it says :
Test
The test form is only available for requests from the local machine.
I do not know if this has an effect or not but when I try to get data from my database using android app I got no error and no data I do not know if there is an error in my code. those are the WCF file code :
my AndroidWebService.asmx code :
<WebMethod(MessageName:="OpenAccount", Description:="this method create new account in the database"), _
System.Xml.Serialization.XmlInclude(GetType(ContactResult))> _
Public Function OpenAccount(ByVal Num As String, ByVal Pass As String) As ContactResult
Dim ds As New DataSet
Dim cr As New ContactResult
Try
Dim data As String
Dim openCon As New SqlConnection("Data Source=SQL5013.site4now.net;Initial Catalog=my initial;User Id=my admin id;Password=my password;")
Dim da As SqlDataAdapter = New SqlDataAdapter("select * from Password", openCon)
Dim saveStaff As String = "select Spec from Password where Num = @AndroidNum AND Pass = @AndroidPass"
Dim querySaveStaff As SqlCommand = New SqlCommand(saveStaff)
querySaveStaff.Connection = openCon
querySaveStaff.Parameters.Clear()
querySaveStaff.Parameters.AddWithValue("@AndroidNum", Num)
querySaveStaff.Parameters.AddWithValue("@AndroidPass", Pass)
openCon.Open()
querySaveStaff.ExecuteNonQuery()
ds.Clear()
da.Fill(ds, "Password")
data = ds.Tables("Password").Rows(0).Item(2).ToString
openCon.Close()
cr.ErrorID = 0
cr.ErrorMessage = data
Return cr
Catch ex As Exception
cr.ErrorID = 1
cr.ErrorMessage = ex.Message
Return cr
End Try
End Function
End Class
my ContactResult class return ErrorID and ErrorMessage :
Public Class ContactResult
Public Property ErrorID As Integer
Public Property ErrorMessage As String
End Class
in android side there are : ContactResult java class :
public class ContactResult {
public static int ErrorID;
public static String ErrorMessage;
}
and LoginActivity java class :
public class LoginActivity extends AppCompatActivity {
private static final String TAG = "LoginActivity";
private static final int REQUEST_SIGNUP = 0;
@BindView(R.id.input_email)
EditText _emailText;
@BindView(R.id.input_password) EditText _passwordText;
@BindView(R.id.btn_login)
Button _loginButton;
@BindView(R.id.link_signup)
TextView _signupLink;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
_loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
login();
}
});
_signupLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), SignupActivity.class);
startActivityForResult(intent, REQUEST_SIGNUP);
finish();
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
}
});
}
public void login() {
Log.d(TAG, "Login");
if (!validate()) {
onLoginFailed();
return;
}
_loginButton.setEnabled(false);
final ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this,
R.style.AppTheme_Dark_Dialog);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("checking...");
progressDialog.show();
String email = _emailText.getText().toString();
String password = _passwordText.getText().toString();
final EditText txtname=(EditText)findViewById(R.id.editName);
final EditText txtphone=(EditText)findViewById(R.id.editPhone);
TextView txtresult=(TextView)findViewById(R.id.textView2);
Thread runt=new Thread(){
public void runt(){
CallWebservice cweb=new CallWebservice();
cweb.OpenAccount(txtname.getText().toString(),txtphone.getText().toString());}
};
runt.start();
runt.join();
txtresult.setText(ContactResult.ErrorMessage);
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
onLoginSuccess();
progressDialog.dismiss();
}
}, 300);
}
public void onLoginSuccess() {
_loginButton.setEnabled(true);
finish();
}
public void onLoginFailed() {
Toast.makeText(getBaseContext(), "login error", Toast.LENGTH_LONG).show();
_loginButton.setEnabled(true);
}
public boolean validate() {
boolean valid = true;
String password = _passwordText.getText().toString();
if (password.isEmpty() || password.length() < 4 || password.length() > 10) {
_passwordText.setError("password not right !");
valid = false;
} else {
_passwordText.setError(null);
}
return valid;
}*/
}
and finally MainActivity code :
public class MainActivity extends AppCompatActivity {
Button loginButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loginButton=(Button)findViewById(R.id.btn_login);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buadd();
}
});
}
public void buadd(){
final EditText txtname=(EditText)findViewById(R.id.editName);
final EditText txtphone=(EditText)findViewById(R.id.editPhone);
TextView txtresult=(TextView)findViewById(R.id.textView2);
Thread runt=new Thread(){
public void runt(){
CallWebservice cweb=new CallWebservice();
cweb.OpenAccount(txtname.getText().toString(),txtphone.getText().toString());}
};
runt.start();
try{
runt.join();
txtresult.setText(ContactResult.ErrorMessage);
}
catch(Exception ex){
}
}
}
What I have tried:
check connection string and re-upload the site !