I have a problem, I can not invoke a Web Service made in C # from an AJAX call using Javascript and jQuery.
This is the call:
function authenticate() {
var name = $("#username").val();
var pwd = $("#password").val();
var baseurl = getbaseurl();
$.ajax({
//url: getlocalurl() + "WebServices/Seguridad.asmx/Autenticar",
url: "http://localhost:59952/WebServices/Seguridad.asmx",
type: 'POST',
data: {
usuario: name,
clave: pwd
},
contentType: "application/json; charset=utf-8",
dataType: 'json',
async: false,
crossdomain: true,
success: OnSuccess,
//traditional: true,
error: function (result) {
$("#errorLabel").show();
$("#password").val("");
}
});
}
This is the Web Service method:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class Seguridad : IntranetWebService.IntranetWebService
{
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void Autenticar(string usuario, string clave)
{
try
{
Usuario entidadUsuario = ControladorSeguridad.ValidarUsuario(usuario, clave);
// Si se autentica, se graba en el registro del usuario, el session Id correspondiente para validar los accesos de los servicios web
if (entidadUsuario.Id > -1)
{
sessionId = System.Guid.NewGuid().ToString();
ControladorSeguridad.GrabarSessionId(entidadUsuario.Id, sessionId);
FachadaSesion.UsuarioAutenticado = entidadUsuario;
InicializarDti(0, JsonConvert.SerializeObject(entidadUsuario), sessionId);
}
else
InicializarDti(LoginErroneo, "", ERROR);
}
catch (System.Exception ex)
{
InicializarDti(Excepcion, ex.Message, EXCEPTION);
}
finally
{
RetornarDatos();
}
}