The below is the declaration of WCF RESTful service for GET
[OperationContract]
[WebGet(UriTemplate= "MemberSearch/{MemberName}", ResponseFormat=WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped)]
string MemberSearch(string MemberName);
The below is the RESTful Service I have created
public string MemberSearch(string MemberName)
{
string MemberId = string.Empty;
string strSqlConn = string.Empty;
SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlCon"].ConnectionString);
sqlCon.Open();
SqlCommand sqlCom = new SqlCommand("Select MemberId From Member Where MemberName Like '%" + MemberName + "%'");
sqlCom.CommandType = System.Data.CommandType.Text;
sqlCom.Connection = sqlCon;
SqlDataReader rd = sqlCom.ExecuteReader();
while (rd.Read())
{
MemberId = Convert.ToString(rd["MemberId"]);
}
return MemberId;
}
The below is the data in the table
MemberId MemberName
1 John
2 Mike
3 Gracy
4 Smith
The below is the calling code in AngularJS
var app = angular.module("app", []);
app.controller("main", function ($scope, $http) {
var MemberName = "Jo";
$scope.keyword = '';
$scope.GetAllData = function () {
$http.get('http://localhost/MemberEligibilityDemo/MemberService.svc/MemberSearch/' + MemberName)
.success(function (data, status, headers, config) {
$scope.Details = data;
})
.error(function (data, status, header, config) {
$scope.ResponseDetails = "Data: " + data +
"<br />status: " + status +
"<br />headers: " + jsonFilter(header) +
"<br />config: " + jsonFilter(config);
});
};
});
The Angular code does not either come into success or error for this
The URLs are as below
http://localhost/MemberEligibilityDemo/MemberService.svc/MemberSearch/
Calling location is as follows
http://localhost/Caller
The result from WCF RESTful service is as below
{"MemberSearchResult":"1"}
EDIT
The calling location is as below
<body ng-app="app">
<table id="tblContainer" ng-controller="main">
<tr>
<td><input type="button" name="DisplayDetails" value="Display Details" ng-click="GetAllData()"></td>
</tr>
<tr>
<td>
<p ng-bind="ResponseDetails"></p>
{{ResponseDetails}}
</td>
</tr>
</table>
Why it is not executing either success or error in AngularJS code.