consume Webservice Async DataTAble

Hello all, I do not know why these code do not work. I know the webservice works because in a console project, it works (with synchronous), however here it do not. Here my code :

public interface IService1
{

    [OperationContract]
    Task<DataTable> GetDataEzra(string command,DataTable tab);
}

public async Task GetDataEzra(string command,DataTable tab)
{
string ConnectionSQL = "Data Source=XX.XX.XXX.XXX;Integrated Security=False;User ID=XXX;Password=XXX;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
SqlConnection myConnection = new SqlConnection(ConnectionSQL);
SqlCommand myCommand = new SqlCommand(command, myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
SqlDataAdapter sda = new SqlDataAdapter(myCommand);
sda.Fill(tab);
myConnection.Close();
var task = Task.Factory.StartNew(() => tab);
return await task;
}
public Courses()
{
courses = new ObservableCollection();
ListView lstView = new ListView();
DataTable dt = new DataTable();

        var legumes = new ArticleGroupModel() { LongName = "Catégorie Légumes", ShortName = "l" };
        var fruits = new ArticleGroupModel() { LongName = "Catégorie Fruits", ShortName = "f" };
        var task = Task.Factory.StartNew(() => GetResult("GetArticles", dt));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                fruits.Add(new ArticleModel { Nom = dt.Rows[i][0].ToString(), Type = "Fruit", Image = "tomato.png", Commentaire = "bien frais" });
            }
        courses.Add(legumes);
        courses.Add(fruits);

        lstView.ItemsSource = courses;
        lstView.IsGroupingEnabled = true;
        lstView.GroupDisplayBinding = new Binding("LongName");
        lstView.GroupShortNameBinding = new Binding("ShortName");
        lstView.ItemTemplate = new DataTemplate(typeof(Article));

        Content = new StackLayout
        {
            Children = {
                lstView
            }
        };

    }
    async static Task GetResult(string command, DataTable tab)
    {
        Service1Client MyClient = new Service1Client();
        var task = Task.Factory.StartNew(() => MyClient.GetDataEzraAsync(command,tab));
        await Task.WhenAny(task, Task.Delay(3500));
    }

Do you have any idea ? I am a really beginner in Xamarin ... There is not erors in compilation but it is like the webservice is not call.

Thank you.

Answers

Sign In or Register to comment.