Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace WcfService1
- {
- [ServiceContract]
- public interface IService1
- {
- [OperationContract]
- [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetUserDetails")]
- string GetUserDetails();
- }
- }
- <script type="text/javascript">
- $(document).ready(function () {
- $('#BtnGetData').click(function () {
- debugger;
- $.ajax({
- type: "GET",
- contentType: "application/json; charset=utf-8",
- url: 'http://localhost:22727/Service1.svc/GetUserDetails',
- data: "{}",
- dataType: "json",
- success: function (data) {
- $($.parseJSON(data.d)).each(function (index, value) {
- $("#tbDetails").append("<tr><td>" + value.Name + "</td><td>" + value.Email + "</td><td>" + value.Category + "</td><td>" + value.Mobile + "</td><td>" + value.Message + "</td></tr>");
- });
- },
- error: function (result) {
- alert(result);
- }
- });
- });
- });
- </script>
- public string GetUserDetails(string UserName, string Password)
- {
- if (UserName == "Admin" && Password == "123")
- {
- string file = AppDomain.CurrentDomain.BaseDirectory + "\DataFile.xml";
- DataSet ds = new DataSet();
- JavaScriptSerializer serializer = new JavaScriptSerializer();
- List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
- Dictionary<string, object> row;
- ds.ReadXml(file);
- foreach (DataRow item in ds.Tables[0].Rows)
- {
- row = new Dictionary<string, object>();
- foreach (DataColumn col in ds.Tables[0].Columns)
- {
- row.Add(col.ColumnName, item[col]);
- }
- rows.Add(row);
- }
- return serializer.Serialize(rows);
- }
- else
- {
- return "null";
- }
- }
- "[{"Name" :"Nimit","Email:test@test.com"...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement