0

Im consuming a RESTful Api builded with ASP EF. I have a procedure in my DB, this is it:

ALTER PROCEDURE [Ventas].[CtasxCobxVendedor]
@AGE CHAR(1),
@VENDEDOR VARCHAR(10)
AS
BEGIN
    SET NOCOUNT ON
     SELECT
    V.CLIENTE Codigo,
    C.RazonSocialAnalitico Cliente,
    C.DireccionAnalitico Direccion,
    C.TelefonoAnalitico Telefono,
    V.Gestion,
    V.IdDos,
    V.DCTO,
    V.Factura,
    V.Fecha,
    V.Vencimiento,
    SUM(B.DBB) Monto,
    SUM(B.HBB) Pagos,
    SUM(B.DBB-B.HBB) Saldo
FROM VENTAS.VMAESTRO V
JOIN VENTAS.CTASXCOBRAR B ON
    (V.GESTION=B.GESTIONF
    AND V.AGE =B.AGE
    AND V.TIPO = B.TIPOF
    AND V.IDDOS = B.IDDOSF
    AND V.DCTO = B.DCTOF)
JOIN VENTAS.vwCLIENTES C ON
    (V.CLIENTE = C.IdAnalitico)
WHERE
--  V.AGE =@AGE
    V.STA = 'A'
    AND V.VENDEDOR = @VENDEDOR
GROUP BY V.CLIENTE,C.RazonSocialAnalitico,C.DireccionAnalitico,C.TELEFONOAnalitico,V.Gestion,V.IdDos,V.DCTO,V.Factura,V.FECHA,V.VENCIMIENTO
HAVING SUM(B.DBB-B.HBB) > 0.001
ORDER BY C.RazonSocialAnalitico, V.FECHA, V.DCTO;
RETURN 0;
END

I created the import function, and the Complex Type on VS. So this is what I got:

    public virtual ObjectResult<CtasxCobxVendedor_Result> CtasxCobrarV(string aGE, string vENDEDOR)
    {
        var aGEParameter = aGE != null ?
            new ObjectParameter("AGE", aGE) :
            new ObjectParameter("AGE", typeof(string));

        var vENDEDORParameter = vENDEDOR != null ?
            new ObjectParameter("VENDEDOR", vENDEDOR) :
            new ObjectParameter("VENDEDOR", typeof(string));

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<CtasxCobxVendedor_Result>("CtasxCobrarV", aGEParameter, vENDEDORParameter);
    }

Then I tried to call this SP in one of my controllers, in this case is my Personal controller, like this:

 public IQueryable<CtasxCobxVendedor_Result1> GetCuenta(string id)
       {
        using (NemesisEntities ctx = new NemesisEntities()) {
        return db.CtasxCobxVendedor("A", id).AsQueryable();
       }
    }

When I call this method on the browser (like this "localhost:45896/api/personals/3329672" where "3329672" is the Personal Id) works just fine, cause it gives me this result:

[{"Codigo":"1018389023","Cliente":"BAREMSA","Direccion":"Av. Cicunvalación - ITOS S/N","Telefono":"","Gestion":"15","IdDos":503,"DCTO":15001980,"Factura":1097,"Fecha":"2015-10-21T00:00:00","Vencimiento":"2015-11-20T00:00:00","Monto":1380.0000,"Pagos":0.0000,"Saldo":1380.0000},{"Codigo":"1018389023","Cliente":"BAREMSA","Direccion":"Av. Cicunvalación - ITOS S/N","Telefono":"","Gestion":"15","IdDos":509,"DCTO":15002329,"Factura":128,"Fecha":"2015-12-09T00:00:00","Vencimiento":"2016-01-08T00:00:00","Monto":1980.0000,"Pagos":0.0000,"Saldo":1980.0000},{"Codigo":"3095060012","Cliente":"BERTHA CONDORI      ORURO","Direccion":"","Telefono":"     25288136","Gestion":"15","IdDos":509,"DCTO":15002349,"Factura":148,"Fecha":"2015-12-11T00:00:00","Vencimiento":"2016-01-10T00:00:00","Monto":1450.0000,"Pagos":0.0000,"Saldo":1450.0000},{"Codigo":"1015777022","Cliente":"CADEXNOR","Direccion":"","Telefono":"","Gestion":"16","IdDos":509,"DCTO":16000384,"Factura":661,"Fecha":"2016-03-09T00:00:00","Vencimiento":"2016-04-08T00:00:00","Monto":1440.0000,"Pagos":0.0000,"Saldo":1440.0000},{"Codigo":"1006965023","Cliente":"COMIBOL","Direccion":"Plaza 6 de Agosto","Telefono":"     68224768","Gestion":"14","IdDos":10,"DCTO":14000142,"Factura":314,"Fecha":"2012-08-03T00:00:00","Vencimiento":"2012-08-08T00:00:00","Monto":2770.0000,"Pagos":0.0000,"Saldo":2770.0000},{"Codigo":"1006965023","Cliente":"COMIBOL","Direccion":"Plaza 6 de Agosto","Telefono":"     68224768","Gestion":"14","IdDos":10,"DCTO":14000143,"Factura":776,"Fecha":"2013-10-03T00:00:00","Vencimiento":"2013-11-02T00:00:00","Monto":2900.0000,"Pagos":0.0000,"Saldo":2900.0000}]

Then when I try to connect it to my Android app using Volley framework:

 JsonArrayRequest re= new JsonArrayRequest(Request.Method.GET, newURL, (String)null, new Response.Listener<JSONArray>() {
       @Override
       public void onResponse(JSONArray response) {
          Toast.makeText(Cobrar.this,response.toString(),Toast.LENGTH_LONG).show();
           procesarRespuesta(response);
       }
   }, new Response.ErrorListener() {
       @Override
       public void onErrorResponse(VolleyError error) {
           Toast.makeText(Cobrar.this,"NOTHING",Toast.LENGTH_LONG).show();
           Log.d(TAG, "Error Volley: " + error.getMessage());
       }
   });

Where "newURL" is like the one above. Just Give me "Error Volley:null" without any other explanation.

I really dont know what to fix, cause when I use simple GET calls for example calling this: "http://localhost:45896/api/clientes", it works fine, the problem is when I want to use the SP.

Any idea of what am I doind wrong? Since I dont get any information of where my problem actually is, Idk where to start

1 Answers1

1

Please check this question posted here.

I have faced same issue.

Why this happens?

In volley, When timeout/socket timeout occurs it throws error. but error object is null. You can override two methods in your Request class to check if its timeout.

Solution :

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, "url", "request", new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }) {
            @Override
            protected void deliverResponse(JSONObject response) {
                super.deliverResponse(response);
            }

            @Override
            public void deliverError(VolleyError error) {
                super.deliverError(error);
            }
        };

You can get error on deliverError method in above code.

TimeOut occurs when server takes more time to respond to app then defined in RetryPolicy.

request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 48,
                0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
  • default timeout is 2500 seconds for Volley.

You can avoid this issue using following improvements :

  1. You need to improve your server performance
  2. You can set retryCount to 1 if it suits your app requirements.

Thanks.

Community
  • 1
  • 1
AndiGeeky
  • 11,266
  • 6
  • 50
  • 66
  • @ Daniel Arteaga Iriarte : I had spent a lot of time for this issue. So do not want other's to go through same..!! :D – AndiGeeky May 12 '16 at 06:51