1

I have a local WEB API in c# running in VS17, that runs and accesses a DB in SQL express using the basic HTTP methods.

And on the other hand I want (have the basics of) an android app that is supposed to access the API and just produce a simple GET requests (currently using Retrofit) and then display the data that was retrieved. Everything works fine on the back-end (tested with postman).

But I haven't had any success in being able to access my API via the app. Any guidance on where I need to look to or how to start would be great!

Notes: API is locally hosted SQLEXpress DB is local Android Device is an emulator I need to use SQLExpress as to SQlite private final String BASE_URL = "http://10.0.2.2:60060";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    listView = (ListView)findViewById(R.id.pagination_list);

    Retrofit.Builder builder = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create());

    Retrofit retrofit = builder.build();

    EmployeeAPIClient client = retrofit.create(EmployeeAPIClient.class);

    Call<List<Employee>> call = client.allEmployees();

    call.enqueue(new Callback<List<Employee>>() {
        @Override
        public void onResponse(Call<List<Employee>> call, Response<List<Employee>> response) {
            List<Employee> employees = response.body();

            Log.w("MainAct onResponse():", " response method called.");
            if(employees.size() <= 0){
                Log.w("EMPTY", " List is empty..");
            }else {
                for(Employee emp: employees){
                    Log.d("FirstName: " , emp.getFirstName());
                    Log.d("LastName: " , emp.getLastName());
                    Log.d("Gender: " , emp.getGender());
                    Log.d("Salary: " , emp.getSalary());
                }
                //listView.setAdapter(new EmployeeAdapter(MainActivity.this, employees));
            }
Jonathan Applebaum
  • 5,738
  • 4
  • 33
  • 52
  • What have you tried so far to get the app to access the API? – Vitor M. Barbosa Jun 25 '18 at 18:25
  • Thats what I am trying to get at, what I know thus far is that you can't access a local API as you would say a https://api.githhub.com, What I think needs to be done is use ports and a local IP, but i havent' had any luck with that (or even being able to check if it did connect or not). – Ricardo96MC Jun 25 '18 at 18:29
  • Our extension Conveyor is generally well received, it makes this possible -> https://visualstudiogallery.msdn.microsoft.com/a429dbb7-a982-4541-b401-934375c02c0f – Jim W Jun 27 '18 at 19:37

1 Answers1

0

IISExpress does not natively suppport remote requests. You will have to do some tweekings to make it work:

Here you got an excelent explanation of how to do it: https://stackoverflow.com/a/3364468/637840

NicoRiff
  • 4,803
  • 3
  • 25
  • 54