Hello altogether,
With the help of https://code.msdn.microsoft.com/windowsapps/How-to-access-data-from-935e360c, I created successfully a service which reads from database. When testing it with the Windows App as recommended, everything works perfect.
Now I want to consume this service not with Windows-App, but with my Xamarin.Android app. Unfortunately, I am lacking of the ServiceClient-class:
try
{
ServiceClient client = new ServiceClient();
IList<Standort> standortListe = await client.QueryAdresseAsync();
}
catch (Exception ex)
{
}
Can anyone maybe tell me if there is something similar in Xamarin.Android and how to be able to consume this service and display the received data (adrList) on e.g. a ListView or (as it is only one row) a TextView or something?
That would really be very kind.
I will share the code of the service, too, maybe it helps a little to understand.
IService.cs
[ServiceContract]
public interface IService
{
[OperationContract]
IList<Standort> QueryAdresse();
}
Service.svc.cs:
public class Service1 : IService
{
public string SqlConStr = "Data Source=[ipadress]\\[instance_name];Initial Catalog=[dbname];user id=[dbusr];password=[dbpw];";
public IList<Standort> QueryAdresse()
{
DataSet ds = new DataSet();
using (SqlConnection sqlCon = new SqlConnection(SqlConStr))
{
try
{
sqlCon.Open();
string sqlStr = "select adrsuche1 from adressen";
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlStr, sqlCon);
sqlDa.Fill(ds);
}
catch
{
return null;
}
finally
{
sqlCon.Close();
}
}
List<Standort> adrList = new List<Standort>();
DataTable dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
adrList.Add(new Standort()
{
Adresse = dr["adrsuche1"] as string,
});
}
return adrList;
}
Thanks in advance for everything,
Best regards