0

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:

  1. The solution project structure looks like: Solution Explored Visual Studio 2019
  2. I start Instance one Visual Studio 2019 And Run SignalRGB.Web enter image description here

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();
        }
  1. 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?

Mark Wardell
  • 493
  • 7
  • 25
  • have you tried using the IP instead of localhost? I don't know about UWP but usually that causes problems with iOS and Android – Jason Jul 04 '20 at 17:57
  • Went to command line: (1) ipConfig yielded 192.168.77.113 (2) ping 192.168.77.113 succeeded (3) Ran Server project it showed browser correctly https://localhost:44300/api/item (4) replaced with https://192.168.77.113:44300/api/item Browser returned 'Bad Request' – Mark Wardell Jul 04 '20 at 18:30
  • do you have your server setup to work with remote requests? – Jason Jul 04 '20 at 18:38
  • I am doing this all locally. I run one instance of Visual studio pressing run button 'IISExpress' in VS 2019 toolbar – Mark Wardell Jul 04 '20 at 18:58
  • All the source code is available here https://github.com/BicycleMark/SignalRGB – Mark Wardell Jul 04 '20 at 18:58
  • I have tried turning Win 10 firewall off in settings. No luck there too :( – Mark Wardell Jul 04 '20 at 19:02

1 Answers1

0

Oversight? in the templated code perhaps. 44300 is the port but notice the protocol.

DeviceInfo.Platform == DevicePlatform.Android ? "https://localhost:44300" :

  • Hey Patrick: Thanks for your attempt. I have now put your attempt on the list of thisngs i tried which did not work. The source is up there. If you pull it down maybe we could determine if it is just my system... – Mark Wardell Jul 09 '20 at 16:54