Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to consume a locally hosted api(IIS EXPRESS) with android simulator

AustyAusty Member ✭✭✭

l did some research and l was told l had to edit the applicationhost.config file and bind the local ip of my computer. after running ipconfig to get the ip of
my local computer(192.168.56.1) l edited the applicationhost.config file as below

    <site name="FINALKAHPROJECT" id="2">
                    <application path="/" applicationPool="Clr4IntegratedAppPool">
                        <virtualDirectory path="/" physicalPath="C:\Users\SBSC QA TEAM\source\repos\FINALKAHPROJECT\FINALKAHPROJECT\FINALKAHPROJECT" />
                    </application>
                    <bindings>
                        <binding protocol="http" bindingInformation="*:56745:localhost" />
                         <binding protocol="http" bindingInformation="*:8080:192.168.56.1" />
                    </bindings>
                </site>

and below is the code in xamarin.forms for consuming the api

 public async void Comic()
        {
            using(var httpClient = new HttpClient()){
                var response = await httpClient.GetStringAsync("http://192.168.56.1:80/api/comic");
                var comic = JsonConvert.DeserializeObject<List<Comic>>(response);
                comicList.ItemsSource = comic;
            }
        }

l get the error System.Net.WebException: 'Failed to connect to /192.168.56.1:80' after setting the solution to start multiple projects and running the webapp and mobile app as the same time.Help Please

Answers

  • matrixlukanmatrixlukan Member ✭✭✭
    edited October 2019

    I had similar issue. After surfing what I found is problem was at the backend. In API project add UseUrls("http://0.0.0.0:80") in your builder. Specifying 0.0.0.0 binds your application to all IP.

    From my knowledge :- 8080 is for https and 80 is used for http.

    If your application is requesting for a service hosted in same mahcine (ie, both android emulator and api project is in same machine) then var response = await httpClient.GetStringAsync("http://10.10.0.0:80/api/comic");.
    Note : 10.10.0.0 redirects to localhost

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭✭

    Hello all,
    @austy,
    follow perhpas this sample and tell us if it's work fine
    http://www.nullskull.com/a/10476774/consuming-web-services-using-xamarin.aspx

    this sample call an asmx with the emulator, i've find and all work

Sign In or Register to comment.