如何从Angular js脚本中调用WCF服务WebGet方法

时间:2016-05-19 08:24:35

标签: c# angularjs

public interface IService1
{
    [OperationContract]
    [WebGet(BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json,
         ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetEmployeeA?id={id}")]
    EmployeeA GetEmployeeA(int id);

    [OperationContract]
    [WebGet(BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetEmployeeJSON?str={str}")]
    string GetEmployeeJSON(string str);
}

我想使用angularJS脚本调用上面的方法...我用param尝试了httpget():

$http({ url: yourURL, method: "GET", params: {: params:" ''} }); 

1 个答案:

答案 0 :(得分:1)

具体问题是什么?如果你这样做,它应该工作得很好:

$http({
    url: "http://yourURL/GetEmployeeA", 
    method: "GET",
    params: {id: 123}
});

RESP。

$http({
    url: "http://yourURL/GetEmployeeJSON", 
    method: "GET",
    params: {str: 'foo'}
});