Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2017
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. namespace WcfService1
  2. {
  3. [ServiceContract]
  4. public interface IService1
  5. {
  6. [OperationContract]
  7. [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetUserDetails")]
  8. string GetUserDetails();
  9. }
  10. }
  11.  
  12. <script type="text/javascript">
  13. $(document).ready(function () {
  14. $('#BtnGetData').click(function () {
  15. debugger;
  16. $.ajax({
  17. type: "GET",
  18. contentType: "application/json; charset=utf-8",
  19. url: 'http://localhost:22727/Service1.svc/GetUserDetails',
  20. data: "{}",
  21. dataType: "json",
  22. success: function (data) {
  23. $($.parseJSON(data.d)).each(function (index, value) {
  24. $("#tbDetails").append("<tr><td>" + value.Name + "</td><td>" + value.Email + "</td><td>" + value.Category + "</td><td>" + value.Mobile + "</td><td>" + value.Message + "</td></tr>");
  25. });
  26. },
  27. error: function (result) {
  28. alert(result);
  29. }
  30. });
  31. });
  32. });
  33. </script>
  34.  
  35. public string GetUserDetails(string UserName, string Password)
  36. {
  37. if (UserName == "Admin" && Password == "123")
  38. {
  39. string file = AppDomain.CurrentDomain.BaseDirectory + "\DataFile.xml";
  40. DataSet ds = new DataSet();
  41. JavaScriptSerializer serializer = new JavaScriptSerializer();
  42. List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
  43. Dictionary<string, object> row;
  44. ds.ReadXml(file);
  45. foreach (DataRow item in ds.Tables[0].Rows)
  46. {
  47. row = new Dictionary<string, object>();
  48. foreach (DataColumn col in ds.Tables[0].Columns)
  49. {
  50. row.Add(col.ColumnName, item[col]);
  51. }
  52. rows.Add(row);
  53. }
  54. return serializer.Serialize(rows);
  55. }
  56. else
  57. {
  58. return "null";
  59. }
  60. }
  61.  
  62. "[{"Name" :"Nimit","Email:test@test.com"...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement