C # Web Api Error StatusCode: 500

0

Good I am developing an application that consumes an Api Web Service but when I run it I get Error StatusCode: 500, ReasonPhrase: 'Internal Server Error'

This Is The Api Web Code

The Connection Probe and It Works.

Code C #

[HttpPost]
    [Route("~/api/SingCronizarcxc")]
    [AcceptVerbs("POST")]
    public IHttpActionResult SingCronizarcxc(List<CuentaPorCobrar> Cxcobrar)
    {


        string Command = "INSERT INTO cuentaporcobrar( Numero, Coddoc, Codclte, Cliente, Cedula, Telefono, Movil, Direccion, Referencia, Garante, GaranTetelefono, GaranteCedula, GaranteDireccion, Codprestamo, Cuota, FPago, Codmoneda, Divisa, Valor, Balance, Mora, Atraso, IdReg, Codcontrol, CodMod, Modalidad, RefCodoc, RefNumero, RefCuota, RefIdReg, RefCodcontrol, RefFmov, IdTransaccion, Longitud, Latitud, Comentario, EsSolicitud, LongitudPago, LatitudPago, FultimoPago, MontoUltimoPago, MontoAbono, MoraPagada, Interes, Capital, DiasAtraso, Imagen, Fecha) "
                         + " VALUES (@Numero,@Coddoc,@Codclte,@Cliente,@Cedula,@Telefono,@Movil,@Direccion,@Referencia,@Garante,@GaranTetelefono,@GaranteCedula,@GaranteDireccion,@Codprestamo,@Cuota,@FPago,@Codmoneda,@Divisa,@Valor,@Balance,@Mora,@Atraso,@IdReg,@Codcontrol,@CodMod,@Modalidad,@RefCodoc,@RefNumero,@RefCuota,@RefIdReg,@RefCodcontrol,@RefFmov,@IdTransaccion,@Longitud,@Latitud,@Comentario,@EsSolicitud,@LongitudPago,@LatitudPago,@FultimoPago,@MontoUltimoPago,@MontoAbono,@MoraPagada,@Interes,@Capital,@DiasAtraso,@Imagen,@Fecha)";
        foreach (var item in Cxcobrar)
        {
            if (Jarsoft.TipoConexion <= 1)
            {
                //Si la Conexion es a MySql
                if (!DataAcc.Conectar())
                {
                    return Ok(false);
                }

                MySqlConnection conn = DataAcc.Conn;
                MySqlCommand command = new MySqlCommand(Command, conn);
                #region Parameters
                command.Parameters.Add("@Numero", MySqlDbType.VarChar,12);
                command.Parameters["@Numero"].Value=item.Numero;
                command.Parameters.Add("@Coddoc", MySqlDbType.VarChar, 2);
                command.Parameters["@Coddoc"].Value =item.Coddoc ;
                command.Parameters.Add("@Codclte", MySqlDbType.VarChar, 2);
                command.Parameters["@Codclte"].Value= item.Codclte ;
                command.Parameters.Add("@Cliente",   MySqlDbType.VarChar, 10);
                command.Parameters["@Cliente"].Value= item.Cliente ;
                command.Parameters.Add("@Cedula",   MySqlDbType.VarChar, 20);
                command.Parameters["@Cedula"].Value = item.Cedula;
                command.Parameters.Add("@Telefono", MySqlDbType.VarChar, 20);
                command.Parameters["@Telefono"].Value= item.Telefono;
                command.Parameters.Add("@Movil", MySqlDbType.VarChar, 20);
                command.Parameters["@Movil"].Value= item.Movil ;
                command.Parameters.Add("@Direccion", MySqlDbType.VarChar, 300);
                command.Parameters["@Direccion"].Value= item.Direccion ;
                command.Parameters.Add("@Referencia", MySqlDbType.VarChar, 200);
                command.Parameters["@Referencia"].Value= item.Referencia;
                command.Parameters.Add("@Garante", MySqlDbType.VarChar,100);
                command.Parameters["@Garante"].Value= item.Garante ;
                command.Parameters.Add("@GaranTetelefono",  MySqlDbType.VarChar,50);
                command.Parameters["@GaranTetelefono"].Value = item.GaranTetelefono;
                command.Parameters.Add("@GaranteCedula",MySqlDbType.VarChar,50);
                command.Parameters["@GaranteCedula"].Value=  item.GaranteCedula ;
                command.Parameters.Add("@GaranteDireccion", MySqlDbType.VarChar,300);
                command.Parameters.Add("@Codprestamo", MySqlDbType.VarChar, 12);
                command.Parameters.Add("@Cuota", MySqlDbType.VarChar, 5);
                command.Parameters.Add("@FPago", MySqlDbType.Date);
                command.Parameters.Add("@Codmoneda", MySqlDbType.VarChar,5);
                command.Parameters.Add("@Divisa",  MySqlDbType.Double);
                command.Parameters.Add("@Valor", MySqlDbType.Double);
                command.Parameters.Add("@Balance", MySqlDbType.Double);
                command.Parameters.Add("@Mora", MySqlDbType.Double);
                command.Parameters.Add("@Atraso", MySqlDbType.Double);
                command.Parameters.Add("@IdReg", MySqlDbType.VarChar, 36);
                command.Parameters.Add("@Codcontrol", MySqlDbType.VarChar, 36);
                command.Parameters.Add("@CodMod", MySqlDbType.VarChar, 5);
                command.Parameters.Add("@Modalidad", MySqlDbType.VarChar, 50);
                command.Parameters.Add("@RefCodoc", MySqlDbType.VarChar, 2);
                command.Parameters.Add("@RefNumero", MySqlDbType.VarChar,12);
                command.Parameters.Add("@RefCuota", MySqlDbType.VarChar, 5);
                command.Parameters.Add("@RefIdReg", MySqlDbType.VarChar, 36);
                command.Parameters.Add("@RefCodcontrol", MySqlDbType.VarChar, 36);
                command.Parameters.Add("@RefFmov", MySqlDbType.Date);
                command.Parameters.Add("@IdTransaccion", MySqlDbType.VarChar, 36);
                command.Parameters.Add("@Longitud", MySqlDbType.Double);
                command.Parameters.Add("@Latitud", MySqlDbType.Double);
                command.Parameters.Add("@Comentario", MySqlDbType.VarChar, 300);
                command.Parameters.Add("@EsSolicitud", MySqlDbType.Bit);
                command.Parameters.Add("@LongitudPago", MySqlDbType.Double);
                command.Parameters.Add("@LatitudPago", MySqlDbType.Double);
                command.Parameters.Add("@FultimoPago", MySqlDbType.Date);
                command.Parameters.Add("@MontoUltimoPago", MySqlDbType.Double);
                command.Parameters.Add("@MontoAbono", MySqlDbType.Double);
                command.Parameters.Add("@MoraPagada", MySqlDbType.Double);
                command.Parameters.Add("@Interes", MySqlDbType.Double);
                command.Parameters.Add("@Capital", MySqlDbType.Double);
                command.Parameters.Add("@DiasAtraso", MySqlDbType.Int32);
                command.Parameters.Add("@Imagen", MySqlDbType.MediumBlob);
                command.Parameters.Add("@Fecha", MySqlDbType.Date);

                command.Parameters["@GaranteCedula"].Value = item.GaranteCedula;
                command.Parameters["@GaranteDireccion"].Value = item.GaranteDireccion;
                command.Parameters["@Codprestamo"].Value = item.Codprestamo;
                command.Parameters["@Cuota"].Value = item.Cuota;
                command.Parameters["@FPago"].Value = item.FPago;
                command.Parameters["@Codmoneda"].Value = item.Codmoneda;
                command.Parameters["@Divisa"].Value = item.Divisa;
                command.Parameters["@Valor"].Value = item.Valor;
                command.Parameters["@Balance"].Value = item.Balance;
                command.Parameters["@Mora"].Value = item.Mora;
                command.Parameters["@Atraso"].Value = item.Atraso;
                command.Parameters["@IdReg"].Value = item.IdReg;
                command.Parameters["@Codcontrol"].Value = item.Codcontrol;
                command.Parameters["@CodMod"].Value = item.CodMod;
                command.Parameters["@Modalidad"].Value = item.Modalidad;
                command.Parameters["@RefCodoc"].Value = item.RefCodoc;
                command.Parameters["@RefNumero"].Value = item.RefNumero;
                command.Parameters["@RefCuota"].Value = item.RefCuota;
                command.Parameters["@RefIdReg"].Value = item.RefIdReg;
                command.Parameters["@RefCodcontrol"].Value = item.RefCodcontrol;
                command.Parameters["@RefFmov"].Value = item.RefFmov;
                command.Parameters["@IdTransaccion"].Value = item.IdTransaccion;
                command.Parameters["@Longitud"].Value = item.Longitud;
                command.Parameters["@Latitud"].Value = item.Latitud;
                command.Parameters["@Comentario"].Value = item.Comentario;
                command.Parameters["@EsSolicitud"].Value = item.EsSolicitud;
                command.Parameters["@LongitudPago"].Value = item.LongitudPago;
                command.Parameters["@LatitudPago"].Value = item.LatitudPago;
                command.Parameters["@FultimoPago"].Value = item.FultimoPago;
                command.Parameters["@MontoUltimoPago"].Value = item.MontoUltimoPago;
                command.Parameters["@MontoAbono"].Value = item.MontoAbono;
                command.Parameters["@MoraPagada"].Value = item.MoraPagada;
                command.Parameters["@Interes"].Value = item.Interes;
                command.Parameters["@Capital"].Value = item.Capital;
                command.Parameters["@DiasAtraso"].Value = item.DiasAtraso;
                command.Parameters["@Imagen"].Value = item.Imagen;
                command.Parameters["@Fecha"].Value = item.Fecha;

                #endregion



                //Ejecutar el Comando
                bool ok = command.ExecuteNonQuery() > 0;
                return Ok(ok);
            }
    }

In this way I Execute it.

  Dim ListadoCxc As List(Of CuentaPorCobrar) = New List(Of CuentaPorCobrar)

    Dim Filtro = " Where pr.codempresa='" + JarSoft.Codempresa + "'  and pr.balance>0 "
    Dim datos = GetDatos(Filtro)'Retorna un Datatable
    For Each dr As DataRow In datos.Rows
        Dim itemcxc As CuentaPorCobrar = New CuentaPorCobrar
        itemcxc.Atraso = dr("Atraso") : itemcxc.Balance = dr("Balance") : itemcxc.Capital = dr("Capital")
        itemcxc.Cedula = dr("Cedula") : itemcxc.Cliente = dr("Cliente") : itemcxc.Codclte = dr("Codclte")
        itemcxc.Codcontrol = dr("Codcontrol") : itemcxc.Coddoc = dr("Coddoc") : itemcxc.Codempresa = dr("Codempresa")
        itemcxc.CodMod = dr("CodMod") : itemcxc.Codmoneda = dr("Codmoneda") : itemcxc.Codprestamo = dr("Codprestamo")
        itemcxc.Comentario = dr("Comentario") : itemcxc.Cuota = dr("Cuota") : itemcxc.DiasAtraso = dr("DiasAtraso")
        itemcxc.Direccion = dr("Direccion") : itemcxc.Divisa = dr("Divisa") : itemcxc.EsSolicitud = dr("EsSolicitud")
        itemcxc.Fecha = dr("Fecha") : itemcxc.FPago = dr("FPago") : itemcxc.FultimoPago = dr("FultimoPago")
        itemcxc.Garante = dr("Garante") : itemcxc.GaranteCedula = dr("GaranteCedula") : itemcxc.GaranteDireccion = dr("GaranteDireccion")
        itemcxc.GaranTetelefono = dr("GaranTetelefono") : itemcxc.IdReg = dr("IdReg")
        itemcxc.IdTransaccion = dr("IdTransaccion") : itemcxc.Interes = dr("Interes")
        itemcxc.Latitud = dr("Latitud") : itemcxc.LatitudPago = dr("LatitudPago") : itemcxc.Longitud = dr("Longitud")
        itemcxc.LongitudPago = dr("LongitudPago") : itemcxc.Modalidad = dr("Modalidad") : itemcxc.MontoAbono = dr("MontoAbono")
        itemcxc.Mora = dr("Mora") : itemcxc.MoraPagada = dr("MoraPagada") : itemcxc.Movil = dr("Movil")
        itemcxc.Numero = dr("Numero") : itemcxc.RefCodcontrol = dr("RefCodcontrol") : itemcxc.RefCodoc = dr("RefCodoc")
        itemcxc.RefCuota = dr("RefCuota") : itemcxc.Referencia = dr("Referencia") : itemcxc.RefFmov = dr("RefFmov")
        itemcxc.RefIdReg = dr("RefIdReg") : itemcxc.RefNumero = dr("RefNumero") : itemcxc.Telefono = dr("Telefono")
        itemcxc.Imagen = JarSoft.ImagenToBytes(JarSoft.ImagenFromFile(dr("Imagen")))
        itemcxc.Valor = dr("Valor")
        ListadoCxc.Add(itemcxc)
    Next

    Dim uri As System.Uri = New Uri("http://localhost:7710/")'Servicio Montado en IIS y Esta Corriendo.
    Dim Client As HttpClient = New HttpClient()
    Dim Deserialized = JsonConvert.SerializeObject(ListadoCxc)
    Client.BaseAddress = uri
    Client.DefaultRequestHeaders.Accept.Clear()
    Client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))

    Dim Respuesta As HttpResponseMessage = Await Client.PostAsync("api/SingCronizarcxc", New StringContent(Deserialized, Encoding.UTF8, "application/json"))

Help Please

    
asked by JOSE ANGEL RAMIREZ HERNANDEZ 06.02.2018 в 03:54
source

1 answer

1

You could facilitate us the complete exit of the error, I would believe that the error is because the return Ok ("whatever"); It is not always reachable ...

public IHttpActionResult Metodo(){
    try{
        /// Acá toda tu lógica
        return Ok("Cualquier cosa");
    }catch(Exception ex){
        return InternalServerError(ex);
    }
}
    
answered by 06.02.2018 в 18:15