The Master-Detail template in Xamarin has typically been a great starting point for many of my apps that work with .Net Core Backing Service. For review it has a Dependency service in the Client that allows Mocking of the Azure Backing Service or connection to a real or local service while in development.
The control variable generated by the template is public static bool UseMockDataStore = true;
All Code discussed is completely found here: https://github.com/BicycleMark/SignalRGB
I created a Xamarin Master-Detail project naming it SignalRGB and did the following:
- The solution project structure looks like:
- I start Instance one Visual Studio 2019 And Run SignalRGB.Web
3) Made Note of url: [https://localhost:44300]
4) Opened another Instance of Visual Studio (2) to run client with UseMockDataSource=false
/ The default it displayed results in Client using MockDataSource
5)went to these lines and updated Client for talking to my local server waiting for an http request :
public static string AzureBackendUrl = //DeviceInfo.Platform == DevicePlatform.Android ? "http://10.0.2.2:5000" : "http://localhost:44300"; DeviceInfo.Platform == DevicePlatform.Android ? "http://localhost:44300" : "http://localhost:44300"; public static bool UseMockDataStore = false; public App() { InitializeComponent(); if (UseMockDataStore) { DependencyService.Register<MockDataStore>(); } else { DependencyService.Register<AzureDataStore>(); } MainPage = new MainPage(); }
Went and ran SignalRGB.UWP from VS Instance(2) and client application hung on the line GetStringAsync():
bool IsConnected => Connectivity.NetworkAccess == NetworkAccess.Internet; public async Task<IEnumerable<Item>> GetItemsAsync(bool forceRefresh = false) { if (forceRefresh && IsConnected) { var json = await client.GetStringAsync ($"api/item"); items = await Task.Run(() => JsonConvert.DeserializeObject<IEnumerable<Item>>(json)); } return items; }
I have tried other platforms iOS and get same result:
What Am I doing wrong here?