Error al intentar acceder al servicio WCF utilizando AngularJS $http
. Aquí está el código de AngularJS:
$http({
method: "POST",
url: "http://localhost:59412/ToDoService.svc/SignIn",
params: JSON.stringify({ username: "jay" }),
headers: {
"Content-Type": "application/json"
}
})
.then(function (res) {
console.log(res);
})
Aquí está el código del servicio web WCF (ToDoService.svc.cs):
public void SignIn(string username)
{
}
El código de ToDoService.svc es:
[ServiceContract]
public interface IToDoService
{
[OperationContract]
[WebInvoke(Method = "POST")]
void SignIn(string username);
}
El error mostrado en la consola del navegador es:
POST http://localhost:59412/ToDoService.svc/SignIn?0=%7B&1=%22&10=%22&11=:&12=%22&13=j&14=a&15=y&16=%22&17=%7D&2=u&3=s&4=e&5=r&6=n&7=a&8=m&9=e 500 (Internal Server Error)
NOTA: Funciona bien si elimino los parámetros de la llamada de servicio.
Respuestas
0 para la respuesta № 1reemplazar params
con data
opción
data: JSON.stringify({ username: "jay" })