I am trying to return a generic list from a WCF. But return an "unknown" error. Can anyone help me out to solve this.
in IService.cs
==============
[ServiceContract]
public interface IServiceLP18
{
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
List<lp18wcf.servicelp18.statecls> GetAllStates();
}
in ServiceLP18
=============
public class ServiceLP18 : IServiceLP18
{
public class StateCls
{
public string StateID;
public string StateName;
}
public List<StateCls> GetAllStates()
{
List<StateCls> StateList = new List<StateCls>();
for (int i = 0; i < 10; i++)
{
StateCls tempRow = new StateCls();
tempRow.StateID = i.ToString();
tempRow.StateName = "Sate " + i.ToString();
StateList.Add(tempRow);
}
return StateList;
}
}
====================================
In calling.html page
====================
function CallGetStates() {
$.ajax({
Type : "POST",
url: "http://localhost:50609/ServiceLP18.svc/GetAllStates",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
processdata: true,
success: function (response) {
var statess = response.d;
$.each(statess, function (index, LpStates) {
alert(LpStates.StateName);
});
},
error: ServiceFailed
});
}