I am trying to store all information of my "user" table in wcf. and return it in json format.When i am invoking the service,i can see the entities. But my question is how to call this service in my view.I have tried it calling with ajax but all that shoots is the error message :( plzz help
service.svc.cs
namespace jsonwcf
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
[WebInvoke(
Method = "POST",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest
)]
public List<UserDetails> SelectUserDetails()
{
pasDataContext db = new pasDataContext();
List<UserDetails> results = new List<UserDetails>();
foreach (User u in db.Users)
{
results.Add(new UserDetails()
{
UserID = u.UserID,
EmpName = u.EmpName,
Email = u.EmailID,
UserName = u.UserName,
UserRole = u.UserRole,
Password = u.Password,
Telephone = u .Telephone
});
}
return results;
}
}
}
iservice.cs
namespace jsonwcf
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "users")]
List<UserDetails> SelectUserDetails();
}
[DataContract]
public class UserDetails
{
[DataMember]
public string UserID
{
get;
set;
}
[DataMember]
public string Password
{
get;
set;
}
[DataMember]
public string UserName
{
get;
set;
}
[DataMember]
public string Email
{
get;
set;
}
[DataMember]
public string EmpName
{
get;
set;
}
[DataMember]
public string UserRole
{
get;
set;
}
[DataMember]
public string Telephone
{
get;
set;
}
}
}