Flutter Development in Windows with ASP.NET Web API backend

Yes I have not used my PC for a boat anchor! as I said earlier my backends are in ASP.NET hosted on a Windows server. These days I am using Winhost but have used Azure in the past but always a little nervous about getting big Azure bills. At least Winhost is deterministic in the pricing model but does lack the one feature I really like and that is Azure server side debugging. Of course I never make coding (errors in thinking according to Mr Robot) but if I did this feature of Azure is great, however I am able to do most of my server side stuff against my localHost where I can set breakpoints locally and still run against my hosted database. Yes I still am old fashioned enough to use a database but use Entity framework Code first to hide the SQL stuff. I also include the Identity bits so I can leverage the Login, role etc stuff that it provides. Then I use it to make secure OAuth calls to my Web API methods. of course there are many other solutions out there but this is a .Net blog. I use Android studio on my PC also and it is identical to Mac version.

Git is well integrated into Android Studio so I use it to keep my versions in sync. The one hiccup I ran into was making my API calls from the Android simulator reach my localhost. the trick is to use 10.0.2.2 as it is Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine) . so my api calls in Flutter code uses urls that look like:

http://10.0.2.2:59348/api/Account/Update

however this is not enough if we are using IIS Express as we will get a 400 Bad Request error as IIS is looking for

localhost and not 127.0.0.1. we need to add a line to applicationhost.config file to tell it to look for 127.0.0.1 in addition

to localhost. The applicationhost.config file can be found in the .vs folder of your API solution which is FlutterBackEnd

in my case

above image was lifted from Matt Ruma’s Post With this in place I can debug my server calls on my localhost .
I will now build a simple Flutter login that will use the Identity services of ASP.NET and
demonstrate making a secure call from Flutter. however first we need to look at the excellent
HTTP support in Flutter.

Leave a reply:

Your email address will not be published.

Site Footer

Sliding Sidebar