locked
Can I optimize Xamarin Forms Cross-Platform app which using SOAP web services? RRS feed

  • Question

  • User362534 posted

    First of all if question asked before please excuse me. It's my first question here and coldn't find any solutions about it. I developed a cross-platform xamarin forms app. It uses Microsoft Dynamics SOAP web services. I imported services for both Android and iOS projects seperately cuz i couldn't do it in main project. When I use web service methods, such as ReadMultiple, it takes too much time. 50-100 index long array takes 3-10 seconds to 20-30 seconds depending on data I retrieve. My co-worker, who using same web services in React Native, getting 2000 index long array in 2 seconds. Can I do anything to optimize build or code? I'm using simple codes which reads data and displays it in a new view. I tried async methods also but it didn't worked at all. Our advisor for Microsoft Dynamics told me not to use async methods to get proper responses. Thank you in advance. IOS builds especially works slower.

    Wednesday, June 10, 2020 11:09 AM

All replies

  • User371688 posted

    For this, you can read through the official document and follow the instructions: https://docs.microsoft.com/en-ie/xamarin/cross-platform/data-cloud/web-services/

    This document demonstrates how to consume different web service technologies. Topics covered include communicating with SOAP services.

    Thursday, June 11, 2020 2:49 AM
  • User362534 posted

    Thanks jezh but there is not much information about optimization in there. I already consuming web services, but it's slow.

    Thursday, June 11, 2020 6:39 AM
  • User371688 posted

    Since we haven't reviewed and tested your code,could you please post some code snippet so that we can analyze with it?

    Besides, you could recheck to see if your Internet speed is normal.

    Friday, June 12, 2020 6:17 AM
  • User362534 posted

    Here some example code which brings companies with search.

    ` public void SelectGroup(string type) { if (cg.searchtext != null) { if (cg.searchtext.Length > 2) { cl = new Views.CompanyList(); cl.Title = cg.searchtext;

                    ScrollView CompanyScroll = new ScrollView();
                    Grid CompanyGrid = new Grid();
    
                    CompanyGrid.Padding = new Thickness(25);
                    CompanyGrid.VerticalOptions = LayoutOptions.Start;
                    CompanyGrid.HorizontalOptions = LayoutOptions.FillAndExpand;
                    CompanyGrid.RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Star } };
                    CompanyGrid.ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = GridLength.Star } };
    
                    contacts[] Companies;
                    if (type == "S")
                    {
                        Companies = webServices.GetCompanies(MainActivity.username, "@" + cg.searchtext + "*");
                    }
                    else
                    {
                        Companies = webServices.GetCompanies(MainActivity.username, "@*" + cg.searchtext + "*");
                    }
    
                    Companies = Companies.OrderBy(x => x.Name).ToArray();
    
                    Button BackButton = new Button { Text = "GERI" };
                    BackButton.BackgroundColor = Color.FromHex("#9C9DCC");
                    BackButton.TextColor = Color.White;
                    BackButton.Clicked += delegate { Application.Current.MainPage.Navigation.PopModalAsync(); };
                    CompanyGrid.Children.Add(BackButton, 0, 0);
    
                    Button AddButton = new Button { Text = "SIRKET EKLE" };
                    AddButton.BackgroundColor = Color.FromHex("#9C9DCC");
                    AddButton.TextColor = Color.White;
                    AddButton.Clicked += delegate { AddCompany(); };
                    CompanyGrid.Children.Add(AddButton, 1, 0);
                    Grid.SetColumnSpan(AddButton, 3);
    
                    if (Companies != null)
                    {
                        for (int i = 0; i < Companies.Length; i++)
                        {
                            Button CompanyButton = new Button { Text = Companies[i].Name, CommandParameter = Companies[i].No };
                            CompanyButton.BackgroundColor = Color.FromHex("#9C9DCC");
                            CompanyButton.TextColor = Color.White;
                            CompanyButton.Clicked += (sender, e) => { SelectCompany(((Button)sender).CommandParameter.ToString(), ((Button)sender).Text.ToString()); };
                            CompanyGrid.Children.Add(CompanyButton, 0, i + 1);
                            Grid.SetColumnSpan(CompanyButton, 4);
                        }
                    }
    
                    CompanyScroll.Content = CompanyGrid;
                    cl.Content = CompanyScroll;
                    Application.Current.MainPage.Navigation.PushModalAsync(new NavigationPage(cl));
                }
            }
        }
    
        public contacts[] GetCompanies(string user, string init)
        {
            ContactsService.Credentials = credential;
            usersetupService.Credentials = credential;
    
            string cfc = usersetupService.ReadMultiple(new usersetup_Filter[] { new usersetup_Filter { Criteria = user,
         Field = usersetup_Fields.User_ID } }, null, 1)[0].Contact_Filter_Code;
            return ContactsService.ReadMultiple(new contacts_Filter[] { new contacts_Filter{ Criteria = "Company", 
        Field = contacts_Fields.Type}, new contacts_Filter() {Criteria = cfc, Field = contacts_Fields.Salesperson_Code },
                new contacts_Filter() {Criteria = "<>KSW000000", Field = contacts_Fields.No },
            new contacts_Filter{ Criteria = init, Field = contacts_Fields.Name }  }, null, 1000);
    
        }
    

    `

    Friday, June 12, 2020 6:36 AM
  • User362534 posted

    Here some example about my code

    ' public void SelectGroup(string type) { if (cg.searchtext != null) { if (cg.searchtext.Length > 2) { cl = new Views.CompanyList(); cl.Title = cg.searchtext;

                    ScrollView CompanyScroll = new ScrollView();
                    Grid CompanyGrid = new Grid();
    
                    CompanyGrid.Padding = new Thickness(25);
                    CompanyGrid.VerticalOptions = LayoutOptions.Start;
                    CompanyGrid.HorizontalOptions = LayoutOptions.FillAndExpand;
                    CompanyGrid.RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Star } };
                    CompanyGrid.ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = GridLength.Star } };
    
                    contacts[] Companies;
                    if (type == "S")
                    {
                        Companies = webServices.GetCompanies(MainActivity.username, "@" + cg.searchtext + "*");
                    }
                    else
                    {
                        Companies = webServices.GetCompanies(MainActivity.username, "@*" + cg.searchtext + "*");
                    }
    
                    Companies = Companies.OrderBy(x => x.Name).ToArray();
    
                    Button BackButton = new Button { Text = "GERI" };
                    BackButton.BackgroundColor = Color.FromHex("#9C9DCC");
                    BackButton.TextColor = Color.White;
                    BackButton.Clicked += delegate { Application.Current.MainPage.Navigation.PopModalAsync(); };
                    CompanyGrid.Children.Add(BackButton, 0, 0);
    
                    Button AddButton = new Button { Text = "SIRKET EKLE" };
                    AddButton.BackgroundColor = Color.FromHex("#9C9DCC");
                    AddButton.TextColor = Color.White;
                    AddButton.Clicked += delegate { AddCompany(); };
                    CompanyGrid.Children.Add(AddButton, 1, 0);
                    Grid.SetColumnSpan(AddButton, 3);
    
                    if (Companies != null)
                    {
                        for (int i = 0; i < Companies.Length; i++)
                        {
                            Button CompanyButton = new Button { Text = Companies[i].Name, CommandParameter = Companies[i].No };
                            CompanyButton.BackgroundColor = Color.FromHex("#9C9DCC");
                            CompanyButton.TextColor = Color.White;
                            CompanyButton.Clicked += (sender, e) => { SelectCompany(((Button)sender).CommandParameter.ToString(), ((Button)sender).Text.ToString()); };
                            CompanyGrid.Children.Add(CompanyButton, 0, i + 1);
                            Grid.SetColumnSpan(CompanyButton, 4);
                        }
                    }
    
                    CompanyScroll.Content = CompanyGrid;
                    cl.Content = CompanyScroll;
                    Application.Current.MainPage.Navigation.PushModalAsync(new NavigationPage(cl));
                }
            }
        }'
    

    ' public contacts[] GetCompanies(string user, string init) { ContactsService.Credentials = credential; usersetupService.Credentials = credential;

            string cfc = usersetupService.ReadMultiple(new usersetup_Filter[] { new usersetup_Filter { Criteria = user, Field = usersetup_Fields.User_ID } }, null, 1)[0].Contact_Filter_Code;
            return ContactsService.ReadMultiple(new contacts_Filter[] { new contacts_Filter{ Criteria = "Company", Field = contacts_Fields.Type},
                new contacts_Filter() {Criteria = cfc, Field = contacts_Fields.Salesperson_Code },
                new contacts_Filter() {Criteria = "<>KSW000000", Field = contacts_Fields.No },
            new contacts_Filter{ Criteria = init, Field = contacts_Fields.Name }  }, null, 1000);
    
        }
    

    '

    Friday, June 12, 2020 6:39 AM
  • User362534 posted

    This is how I get searched companies.

    public contacts[] GetCompanies(string user, string init) { ContactsService.Credentials = credential; usersetupService.Credentials = credential; string cfc = usersetupService.ReadMultiple(new usersetup_Filter[] { new usersetup_Filter { Criteria = user, Field = usersetup_Fields.User_ID } }, null, 1)[0].Contact_Filter_Code; return ContactsService.ReadMultiple(new contacts_Filter[] { new contacts_Filter{ Criteria = "Company", Field = contacts_Fields.Type}, new contacts_Filter() {Criteria = cfc, Field = contacts_Fields.Salesperson_Code }, new contacts_Filter() {Criteria = "<>KSW000000", Field = contacts_Fields.No }, new contacts_Filter{ Criteria = init, Field = contacts_Fields.Name } }, null, 1000);}

    Friday, June 12, 2020 6:40 AM
  • User362534 posted

    @jezh said: Since we haven't reviewed and tested your code,could you please post some code snippet so that we can analyze with it?

    Besides, you could recheck to see if your Internet speed is normal.

    Here some code to bring companies with search criteria

    Friday, June 12, 2020 6:45 AM
  • User362534 posted
    public contacts[] GetCompanies(string user, string init)
            {
                ContactsService.Credentials = credential;
                usersetupService.Credentials = credential;
                string cfc = usersetupService.ReadMultiple(new usersetup_Filter[] { new usersetup_Filter { Criteria = user, Field = usersetup_Fields.User_ID } }, null, 1)[0].Contact_Filter_Code;
                return ContactsService.ReadMultiple(new contacts_Filter[] { new contacts_Filter{ Criteria = "Company", Field = contacts_Fields.Type},
                    new contacts_Filter() {Criteria = cfc, Field = contacts_Fields.Salesperson_Code },
                    new contacts_Filter() {Criteria = "<>KSW000000", Field = contacts_Fields.No },
                new contacts_Filter{ Criteria = init, Field = contacts_Fields.Name }  }, null, 1000);
            }
    
    Friday, June 12, 2020 6:48 AM
  • User362534 posted
            public void SelectGroup(string type)
            {
                if (cg.searchtext != null)
                {
                    if (cg.searchtext.Length > 2)
                    {
                        cl = new Views.CompanyList();
                        cl.Title = cg.searchtext;
    
                        ScrollView CompanyScroll = new ScrollView();
                        Grid CompanyGrid = new Grid();
    
                        CompanyGrid.Padding = new Thickness(25);
                        CompanyGrid.VerticalOptions = LayoutOptions.Start;
                        CompanyGrid.HorizontalOptions = LayoutOptions.FillAndExpand;
                        CompanyGrid.RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Star } };
                        CompanyGrid.ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = GridLength.Star } };
    
                        contacts[] Companies;
                        if (type == "S")
                        {
                            Companies = webServices.GetCompanies(MainActivity.username, "@" + cg.searchtext + "*");
                        }
                        else
                        {
                            Companies = webServices.GetCompanies(MainActivity.username, "@*" + cg.searchtext + "*");
                        }
    
                        Companies = Companies.OrderBy(x => x.Name).ToArray();
    
                        Button BackButton = new Button { Text = "GERI" };
                        BackButton.BackgroundColor = Color.FromHex("#9C9DCC");
                        BackButton.TextColor = Color.White;
                        BackButton.Clicked += delegate { Application.Current.MainPage.Navigation.PopModalAsync(); };
                        CompanyGrid.Children.Add(BackButton, 0, 0);
    
                        Button AddButton = new Button { Text = "SIRKET EKLE" };
                        AddButton.BackgroundColor = Color.FromHex("#9C9DCC");
                        AddButton.TextColor = Color.White;
                        AddButton.Clicked += delegate { AddCompany(); };
                        CompanyGrid.Children.Add(AddButton, 1, 0);
                        Grid.SetColumnSpan(AddButton, 3);
    
                        if (Companies != null)
                        {
                            for (int i = 0; i < Companies.Length; i++)
                            {
                                Button CompanyButton = new Button { Text = Companies[i].Name, CommandParameter = Companies[i].No };
                                CompanyButton.BackgroundColor = Color.FromHex("#9C9DCC");
                                CompanyButton.TextColor = Color.White;
                                CompanyButton.Clicked += (sender, e) => { SelectCompany(((Button)sender).CommandParameter.ToString(), ((Button)sender).Text.ToString()); };
                                CompanyGrid.Children.Add(CompanyButton, 0, i + 1);
                                Grid.SetColumnSpan(CompanyButton, 4);
                            }
                        }
    
                        CompanyScroll.Content = CompanyGrid;
                        cl.Content = CompanyScroll;
                        Application.Current.MainPage.Navigation.PushModalAsync(new NavigationPage(cl));
                    }
                }
            }
    
    Friday, June 12, 2020 6:49 AM
  • User362534 posted

    -

    Friday, June 12, 2020 11:00 AM