This is a migrated thread and some comments may be shown as answers.

ERP Sample Application Problem

7 Answers 102 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 10 Feb 2021, 01:37 AM

I have downloaded the sample code, and followed the instructions laid out here:

https://github.com/telerik/telerik-xamarin-forms-samples/tree/master/ERP

 

I have successfully published the service app, and am able to browse to the url just fine.  Additionally, I can see the SQL objects and data got created in the sample database.  I updated the web.config with the Azure SQL Connection info

I have updated the constants.cs file in the ErpApp solution with the URL from the Azure app service as well.

 

However, when I launch the app from debug in VS 2019, all the tabs in the mobile app spin for a few seconds, and then bring up empty screens, almost like there's no data to connect to, or some kind of permissions is not allowing it to pull down the data from Azure SQL.  Interestingly enough, I am able to add a customer, but I have no idea where it's adding it to if it can't connect to the database!

Any thoughts here?   Feels like I'm really close, but something isn't quite hooked up correctly I don't think.

 

7 Answers, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 10 Feb 2021, 03:07 PM

Hi Tim,

Just to make sure, did you follow my instructions here telerik-xamarin-forms-samples/ERP at master ยท telerik/telerik-xamarin-forms-samples (github.com)?

Keep in mind that these Xamarin Mobile Services type apps have 2 data components; online db (the SQL Server) and an offline db (sqlite). So, when you added an item, it is actually being added to the local DB. What is likely failing is the syncing of your local DB and the SQL server.

Troubleshooting Suggestions

Outside of that, I really don't have a "here's your problem" answer, but I can suggest a couple things that might point you in the right direction:

1. Code Breakpoints

Place breakpoints in the code to verify if you are getting expected value

For example, putting a breakpoint in the service class methods will help you identify if values are returning https://github.com/telerik/telerik-xamarin-forms-samples/blob/master/ERP/app/ErpApp/ErpApp/Services/ErpService.cs#L61 

If Data is being returned there, then go check out the view model for the UI https://github.com/telerik/telerik-xamarin-forms-samples/blob/master/ERP/app/ErpApp/ErpApp/ViewModels/CustomersListViewModel.cs#L109 

If that is actually giving you a collection of the items from the table, then the issue is in the UI side of things.

2. Network traffic

Run Fiddler and inspect the actual HTTPS traffic to/from the server

If the app's code isn't helping you see what is going on, then using Fiddler (https://www.telerik.com/fiddler) will let you see the network traffic being sent/received from the server. This is where you would catch and review HTTP 5xx errors.

3. Dependency Versions

Please make sure you have not updated any dependencies in the solution. We developed and tested the app with the exact dependencies being used in the source code as-is. We cannot guarantee that it will still work if you update the version of Xamarin.Forms (or any other packages).

When I wrote the readme tutorial, I can confirm that the exact steps got me up and running from scratch. As long as you didn't change the dependencies, and Microsoft hasn't deprecated the services, then it should work.

4. Refresh/Relaunch

This one is anecdotal. I have noticed in the past with SQL server + Mobile Service setups that it doesn't work the first time. Sometimes, I need to relaunch everything after the DB is created and seeded. Try the following

  1. Uninstall the app (be sure its a real delete, we need everything blasted away)
  2. Reinstall the app

This will delete the local DB and give the local storage a change to start fresh. As long as the server is allowing communication with the client app, then it should resync as a new copy

Further Assistance

If you still have trouble, I recommend you open a technical Support Ticket so that we can loop in the team responsible for building that demo (you have full technical support during your trial, this give you direct access to the team).

Good luck! Let me know if you have any trouble opening a ticket.

Regards,
Lance | Manager Technical Support
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Tim
Top achievements
Rank 1
answered on 11 Feb 2021, 12:31 AM

Thanks Lance, just to confirm yes I was using that same instructions.

So I did some investigation based on what you sent, I am 99% sure that that when I put those breakpoints on that I am not getting any customer data. Now, what I don't know is if that code is supposed to be reading from the Azure SQL, or the offline copy at that point.  It also is a bit confusing to me what SQL Connections get set in web.config in the telikerp app.  The intital web.config setting is the localdb, but then we are supposed to replace it with the Azure SQL; which I assume is correct because the 'Update-Database' command didn't work until I did that.  But then where does it specify the local db setting it needs for the sync if that's now commented out?

So, I will try the refresh/relaunch next but wasn't sure what was meant by "uninstalling the app".  Does that mean the service web app or does that mean the app on the simulated phone in Visual Studio?

0
Lance | Manager Technical Support
Telerik team
answered on 11 Feb 2021, 02:02 PM

Hello Tim,

To understand more about the app, please read the blog post about its construction: Building a Performant ERP App with Telerik UI for Xamarin 

When I mention to uninstall & reinstall, I'm referring to the Xamarin.Forms app.

  • If you deployed to the Android/iOS emulator, then you would uninstall it from the emulator (press and hold the app icon, then select uninstall/delete from the context menu).
  • If you deployed to the local PC, the you right click on the app in the Start menu and select "Uninstall"

Please keep in mind that the mobile app doesn't actually connect to the database directly. Database interactions are done by the ASP.NET project's Web API controller.

In fact this entire solution is database agnostic, you can use any database on the other side of the web API. To help you understand the high level, I've mocked up the structure.

 

> I see you've opened a ticket for 1:1 help in your setup, I have left a note to the devs so that can be aware of what we already discussed. 



Understanding Xamarin Mobile Services approach

I used the same backed technique when building the CRM demo. For that app, I wrote a long-form 3 part blog series. You can also read that it get an understanding of how the setup is configured.

Regards,
Lance | Manager Technical Support
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Tim
Top achievements
Rank 1
answered on 11 Feb 2021, 02:31 PM

Thanks, read through all of that it's really helpful. 

 

I was able to get the data to start showing up on the mobile app after re-deploying the service app, so good progress there.  The only thing not working now is the sync between the offline db and Azure SQL.  So, when I add a customer in the app, I can see it; but when I look in Azure SQL it is not there; which would indicate the sync back up to Azure SQL is not working correctly.  Any ideas there?  thx

0
Lance | Manager Technical Support
Telerik team
answered on 11 Feb 2021, 03:40 PM

Hi Tim,

I took another peek at the ASP.NET app's controllers. https://github.com/telerik/telerik-xamarin-forms-samples/tree/master/ERP/service/telerikerpService/Controllers

The ERP demo's SQL server code is read-only. They only have GET methods for Read operations, you need to finish implementing the rest of the CRUD operations. 

As one example, look at the Customers controller and see there is only a GetAll() and a Get(int cusotmerId).

// THERE ARE ONLY GET METHODS, THIS CODE DOES NOT INSERT/UPDATE/DELETE SQL RECORDS
namespace telerikerpService.Controllers
{
    public class CustomerController : TableController<Customer>
    {
        protected override void Initialize(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);
            telerikerpContext context = new telerikerpContext();
            DomainManager = new EntityDomainManager<Customer>(context, Request);
        }

        // GET tables/Customer
        [ExpandProperty("Addresses")]
        public IQueryable<Customer> GetAllCustomers()
        {
            return Query();
        }

        // GET tables/Customer/48D68C86-6EA6-4C25-AA33-223FC9A27959
        [ExpandProperty("Addresses")]
        [ExpandProperty("Orders")]
        public SingleResult<Customer> GetCustomer(string id)
        {
            return Lookup(id);
        }
    }
}

Solution

The way forward is simple... just finish implementing the rest of the methods. This part is outside what Telerik's resources can help with, which is why we do not have tutorials on SQL server and Web API (it is unrelated to Telerik UI for Xamarin). You will that information is in Azure's and Xamarin's documentation by searching "Xamarin. Mobile app Service"

However, I can give you a head start by looking at the CRM's commented out methods. I left the code in there even though the demo is read-only.

As an example, visit the CRM's Customers controller and see how I return a 500 error if you try to hit any of the CUD methods. Uncomment those

https://github.com/telerik/telerik-xamarin-forms-samples/blob/master/ArtGalleryCRM/ArtGalleryCRMService/Controllers/CustomerController.cs 

namespace ArtGalleryCRMService.Controllers
{
    // IMPORTANT: Before deploying to your Azure account, enable insert, update and delete:
    // 1. Uncomment the code in the Patch, Post and Delete methods.
    // 2. Delete the "throw new HttpException(500, "Demo - Read-only mode");" lines.
    public class CustomerController : TableController<Customer>
    {
        protected override void Initialize(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);

            var context = new ArtGalleryCRMContext();

            DomainManager = new EntityDomainManager<Customer>(context, Request);
        }

        // GET tables/Customer
        public IQueryable<Customer> GetAllCustomers()
        {
            return Query();
        }

        // GET tables/Customer/48D68C86-6EA6-4C25-AA33-223FC9A27959
        public SingleResult<Customer> GetCustomer(string id)
        {
            return Lookup(id);
        }

        // PATCH tables/Customer/48D68C86-6EA6-4C25-AA33-223FC9A27959
        public Task<Customer> PatchCustomer(string id, Delta<Customer> patch)
        {
            // Remove this before deploying to your Azure account.
            throw new HttpException(500, "Demo - Read-only mode");

            // Uncomment before deploying to your Azure account.
            // return UpdateAsync(id, patch);
        }

        // POST tables/Customer
        public async Task<IHttpActionResult> PostCustomer(Customer customer)
        {
            // Remove this before deploying to your Azure account.
            throw new HttpException(500, "Demo - Read-only mode");

            // Uncomment before deploying to your Azure account.
            // Customer current = await InsertAsync(customer);
            // return CreatedAtRoute("Tables", new { id = current.Id }, current);
        }

        // DELETE tables/Customer/48D68C86-6EA6-4C25-AA33-223FC9A27959
        public Task DeleteCustomer(string id)
        {
            // Remove this before deploying to your Azure account.
            throw new HttpException(500, "Demo - Read-only mode");

            // Uncomment before deploying to your Azure account.
            // return DeleteAsync(id);
        }
    }
}

Regards,
Lance | Manager Technical Support
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Lance | Manager Technical Support
Telerik team
answered on 11 Feb 2021, 03:58 PM

Hello,

As a quick follow up, I tried finding the original tutorial from Microsoft that takes you through all of the steps in setting up the backend. It looks like they removed it in their push to decouple Xamarin from the original SQL-only option.

I did find it because I bookmarked the link :) https://docs.microsoft.com/en-us/previous-versions/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started  (you can follow that tutorial to get all the source for the initial project template that has SQL + sqlite working with full CRUD operations).

Here are some of the newer articles I could find that are meant to be the replacement (mostly focuses on Cosmos and MongoDB)

Regards,
Lance | Manager Technical Support
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Tim
Top achievements
Rank 1
answered on 11 Feb 2021, 08:49 PM
Thanks Lance, I think I got it now.  This demo is really great and thanks for putting all the work into it!
Tags
General Discussions
Asked by
Tim
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Tim
Top achievements
Rank 1
Share this question
or