I have a WS REST, that I need to consume by POST, which method "calculo
" expects a XML as below in the key "xmlEntrada
".
<xml>
<valor1/>
<valor2/>
<operacao/>
</xml>
I did the corresponding class to serialize, as expected by retrofit and SimpleXmlConverter
@Root(name="xml")
public class CalcRequest {
public CalcRequest(){
campo1 = campo2 = 0;
operacao = "";
}
@Element(name="valor1", required = false)
private float campo1;
@Element(name="valor2", required = false)
private float campo2;
@Element(name="operador", required = false)
private String operacao;
}
And I'm calling retrofit and all the stuff like this:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://server_name/wsRest/Project1.dll/")
.addConverterFactory(SimpleXmlConverterFactory.create())
.client(new OkHttpClient())
.build();
APIService API = retrofit.create(APIService.class);
Call<CalcResponse> call = API.EfetuaCalculo(calculo);
call.enqueue(new Callback<CalcResponse>() {
@Override
public void onResponse(Call<CalcResponse> call, Response<CalcResponse> response) {
AlertMessage(response.body().retorno());
}
@Override
public void onFailure(Call<CalcResponse> call, Throwable t) {
AlertMessage("Error. MSG: " + t.toString());
}
});
My method response serialization is fine, because I can read the error returned as XML, and it shows me that the request xml is arriving empty at the WS. I'm stucked on that by days, can anyone guess what's wrong?
Oh, here it's my APIService
code:
public interface APIService {
@POST("calculo")
Call<CalcResponse> EfetuaCalculo(@Body CalcRequest xmlEntrada);
}