How can I receive and send data to my ajax from a web service c #?

1

Good morning, I'm getting 500 error when I run my ajax call to a web service, I do not understand the problem very well but I guess it's because I'm getting bad data from the json that I send from my script.

Ajax:

   $.ajax(
{
    url: "http://localhost:54943/ServicioWeb.asmx?op=CancelarReserva",
    data: dataParse,
    dataType: "json",
    type: "POST",
    contentType: "application/json; charset=utf-8",
    success: function (response) {
        console.log(response);
        var resultadoAMostrar = '<p class="alert alert-success">' + response + '</p>';
        $("#error-ajax").html(resultadoAMostrar);
    },
    error: function () {
        var resultadoAMostrar = '<p class="alert alert-danger">ERROR AL CANCELAR LA RESERVA</p>';
        $("#error-ajax").html(resultadoAMostrar);
    }
}); 

And the method of my webservice is the following:

    [WebMethod(EnableSession = true)]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string CancelarReserva(string ReservaId)
    {

        int ReservaInt = Convert.ToInt32(ReservaId);

        Reserva reservaAEliminar = db.Reserva.Find(ReservaInt);
        Usuario u = reservaAEliminar.Usuario;
        string response = String.Empty;

        if (reservaAEliminar.Paquete.FechaInicio > System.DateTime.Now)
        {

            Paquete paquete = db.Paquete.Where(p => p.Id == reservaAEliminar.IdPaquete).FirstOrDefault();


            paquete.LugaresDisponibles = paquete.LugaresDisponibles + reservaAEliminar.CantPersonas;


            db.Reserva.Remove(reservaAEliminar);

            db.SaveChanges();

            response = "La reserva ha sido cancelada";
            return new JavaScriptSerializer().Serialize(response);
        }
        else
        {
            response = "La fecha de reserva ha expirado";
            return new JavaScriptSerializer().Serialize(response);
        }



    }

The error that throws me is the following:

POST http://localhost:54943/ServicioWeb.asmx?op=CancelarReserva 500 (Internal Server Error)

Any idea what it can be?

EDIT: The error is giving me this answer:

"<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="es">System.Web.Services.Protocols.SoapException: El servidor no puede procesar la solicitud. ---&gt; System.Xml.XmlException: Los datos del nivel de raíz no son válidos. línea 1, posición 1.
    
asked by Matías Heredia 16.11.2017 в 04:12
source

0 answers