Angular:使用AngularJS $ http调用WCF服务时出错

时间:2016-03-16 11:31:37

标签: angularjs wcf

尝试使用AngularJS $http访问WCF服务时出错。这是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);
        })

这是WCF Web服务代码(ToDoService.svc.cs):

    public void SignIn(string username)
    {

    }

ToDoService.svc代码是:

[ServiceContract]
public interface IToDoService
{
    [OperationContract]
    [WebInvoke(Method = "POST")]
    void SignIn(string username);
}

浏览器控制台中显示的错误是:

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)

注意:如果我从服务电话中移除了参数,则工作正常。

1 个答案:

答案 0 :(得分:0)

使用params选项

替换data
data: JSON.stringify({ username: 'jay' })
相关问题