0

Just starting to use Retrofit, but I have a few doubts. I can´t avoid a few errors which don´t let me debug my app. So sorry for bother you all.

Well, this is the part of the code which maybe you need to know.

As you all see, Graddle, Interface (for Rest), Pojo Class (with class and parent class which is a list of the first one), and the activity (I call retrofit in onCreate, and I recover Data in onResponse)

--Graddle--
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.google.code.gson:gson:2.5'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'

--Pojo--
public class pisoAlquiler {
private int codigo;
private String fotos;
}

public class pisosAlquiler {
List<pisoAlquiler> pisoAlquilerList;
}

--Interface--
public interface RestApi {
@GET("/Service1.svc?wsdl")
Call<pisosAlquiler> devolverPisosA();
}

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

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("http://localhost:52896")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    // prepare call in Retrofit 2.0
    RestApi restApi = retrofit.create(RestApi.class);

    Call<pisosAlquiler> call = restApi.devolverPisosA();
    //asynchronous call
    call.enqueue(this);
}

@Override
public void onResponse(Call<pisoAlquiler> call, Response<pisoAlquiler> response) {
    setProgressBarIndeterminateVisibility(false);
    // Create a LinearLayout element
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);

    pisosAlquiler prueba = (pisosAlquiler) response.body().pisoAlquilerList;
}

I´m getting two errors, problably coming from the same issue.

In onCreate:

call.enqueue(this);

this returns error saying in Call cannot be applied, if I use pisoAlquiler Class, instead of pisosAlquiler (which contains a list of pisoAlquiler) the error dissapear.

In onResponse:

pisosAlquiler prueba = (pisosAlquiler) response.body().pisoAlquilerList;

pisoAlquilerList returns cannot resolve symbol. Looks like I can call attributes of pisoAlquiler but not the only attribute which pisosAlquiler has it...

Any Ideas?

Thanks Mates.

Kenzo_Gilead
  • 2,187
  • 9
  • 35
  • 60
  • 1
    change `pisosAlquiler prueba = (pisosAlquiler) response.body().pisoAlquilerList`; to this : `pisosAlquiler prueba = (pisosAlquiler) response.body();`. Remember also that according to your POJO - pisoAlquilerList is private - so might not be accessible to the call `.pisoAlquilerList`. – ishmaelMakitla May 25 '16 at 10:33
  • 2
    When you call `call.enqueue(this);` - is your current class (`this`) implementing `Callback` OR does it implement `Callback`? – ishmaelMakitla May 25 '16 at 10:35
  • 1
    You can see my working answers : [1]: http://stackoverflow.com/questions/37098347/how-to-use-gson-2-0-on-onresponse-from-retrofit-2-0/37099604#37099604 [2]: http://stackoverflow.com/questions/36771946/error-when-using-retrofit/36773538#36773538 – Yasin Kaçmaz May 25 '16 at 11:04
  • ishmael... It as that. I forgot I changed Callback to Callback. Everything is worked. Cool!! Anyway, Why don´t you post an answer? I would like reward to efford and rate it... – Kenzo_Gilead May 25 '16 at 11:36

1 Answers1

0

Well,

The problem was I´m in Debbug Mode and WCF (by Visual Studio) and Android Studio wasn´t configurated in the same network.

For configuring Visual Studio for working with Android Studio in a Local Network, following the next:

Web.Config must to be set for listening from differents places. Between services and Behavior tags:

<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

Open applicationhost.config allocated in Project Folder --> Config: Change the next one:

<site name="Proyect" id="2">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="c:\ProjectFolder\Proyect />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:52896:localhost" />
            </bindings>
        </site>

For:

<site name="Proyect" id="2">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="c:\ProjectFolder\Proyect" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:52896:localhost" />
              <binding protocol="http" bindingInformation="*:52896:*" />
            </bindings>
        </site>

With this, We can listen internal request.

Open Windows Firewall for that port.

Kenzo_Gilead
  • 2,187
  • 9
  • 35
  • 60