I am developing a mobile app using xamarin (android). This app is supposed to access an mssql database using wcf. The wcf successfully connects with the database. The problem is that the app doesnt connect with the wcf. I'm using vs2017. The wcf is currently in IIS. Then I succeeded in adding a web reference to the wcf. Its name is JosGum.
My app code
public class ACategory : Activity
{
Button btnTest;
TextView textView1;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.ACategory);
btnTest = FindViewById<Button>(Resource.Id.btnTest);
textView1 = FindViewById<TextView>(Resource.Id.textView1);
btnTest.Text = "Back";
string temp = Intent.GetStringExtra("ButtonClicked") ?? "Item not available";
textView1.Text = "You are viewing the " + temp + " Category. Choises in here will be populated when connected to database";
this.Title = Intent.GetStringExtra("ButtonClicked") ?? "Motor not available";
ListView list = (ListView)FindViewById(Resource.Id.list);
JosGum.Service1 myService = new JosGum.Service1();
myService.AddTBFCompleted += MyService_AddTBFCompleted;
myService.AddTBFAsync(temp);
btnTest.Click += (o, e) =>
{
SetContentView(Resource.Layout.Main);
StartActivity(typeof(MainActivity));
};
}
private void MyService_AddTBFCompleted(object sender, JosGum.AddTBFCompletedEventArgs e)
{
//throw new NotImplementedException();
textView1.Text = e.Error.ToString();
}
}
The WCF code is as follows and works exactly on its own. But it is not listening to the app.
public class Service1 : IService1
{
private string conStr = "server =.; User Id = sa; Password=; Database=Test; trusted_connection=yes";
public List<ToBeFilled> GetToBeFilled()
{
List<ToBeFilled> tBFList = new List<ToBeFilled>();
SqlConnection connection = new SqlConnection(this.conStr);
connection.Open();
SqlCommand cmd = new SqlCommand("select TBF from TestTable", connection);
cmd.CommandType = CommandType.Text;
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
ToBeFilled tBF = new ToBeFilled();
tBF.TBF = sdr["TBF"].ToString();
tBFList.Add(tBF);
}
return tBFList.ToList();
}
public string AddTBF(string tBF)
{
int status = 0;
SqlConnection connection = new SqlConnection(this.conStr);
SqlCommand cmd = new SqlCommand();
try
{
if (connection.State==ConnectionState.Closed)
{
connection.Open();
}
cmd = new SqlCommand("Insert into TestTable (Id,TBF) values (@Id, @TBF)", connection);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Id", tBF);
cmd.Parameters.AddWithValue("@TBF", tBF);
cmd.ExecuteReader();
status = 1;
}
catch(Exception ex)
{
throw ex;
}
finally
{
connection.Close();
cmd.Dispose();
}
return status.ToString();
}
}
The image shows that the wcf is included as a web reference
Help!!!!!!