Please find bellow code .it was executing perfectly and getting the result also perfect ..but my thought is why we want to go for datareader insted of dataset ..here in bellow code am using datareader for fetch the list of the data but i want use these in dataset ..please
IN..
[ServiceContract]
public interface IService
{
[OperationContract(Name = "GetFriendsList")]
[WebGet(UriTemplate = "/GetFriendsList/{DeviceId}", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
List<Friends> GetFriendsList(string DeviceId);
}
[DataContract]
public class Friends
{
public string FriendNumber;
public string Name;
public string STATUSMSG;
public int STATUSIND;
[DataMember]
public string friendNumber {
get { return FriendNumber; }
set { FriendNumber = value; }
}
[DataMember]
public string name {
get { return Name; }
set { Name = value; }
}
[DataMember]
public string status {
get { return STATUSMSG; }
set { STATUSMSG = value; }
}
[DataMember]
public int statuind
{
get { return STATUSIND; }
set { STATUSIND = value; }
}
}
Coming to .svc file
public List<Friends> GetFriendsList(string DeviceId)
{
List<Friends> listFriend = new List<Friends>();
SqlCommand cmd = null;
SqlDataReader reader = null;
Friends friend = new Friends();
try
{
cmd = new SqlCommand("GetFriendsList", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@DeviceId", DeviceId);
conn.Open();
reader = cmd.ExecuteReader();
while(reader.Read())
{
friend.friendNumber = reader["FriendNumber"].ToString();
friend.name = reader["Name"].ToString();
friend.status = reader["STATUSMSG"].ToString();
friend.statuind = Convert.ToInt32(reader["STATUSIND"].ToString());
listFriend.Add(friend);
}
if(listFriend.Count==0)
{
friend.status = "Record Not Found";
friend.statuind = -1;
}
conn.Close();
}
catch (Exception ex)
{
friend.status = ex.Message.ToString();
friend.statuind = -1;
}
return listFriend.ToList();
}
Input is:
http://localhost:7005/Service.svc/GetFriendsList/MTEwMGQ3NDNhMThhMTcyZA==
The Output is:
{
"GetFriendsListResult": [
{
"friendNumber": "123456",
"name": "Prasad",
"statuind": 1,
"status": ""
},
{
"friendNumber": "32546",
"name": "Raja",
"statuind": 1,
"status": ""
},
{
"friendNumber": "369822",
"name": "Roja",
"statuind": 1,
"status": ""
},
{
"friendNumber": "8556665",
"name": "madhu",
"statuind": 1,
"status": ""
},
{
"friendNumber": "9949052820",
"name": "Nanda",
"statuind": 1,
"status": ""
},
{
"friendNumber": "9949052820",
"name": "Nanda",
"statuind": 1,
"status": ""
},
{
"friendNumber": "9949052820",
"name": "Nanda",
"statuind": 1,
"status": ""
},
{
"friendNumber": "985665",
"name": "mohini",
"statuind": 1,
"status": ""
},
{
"friendNumber": "9949052820",
"name": "Nanda",
"statuind": 1,
"status": ""
}
]
}
The Above code executes perfects and am getting result also perfect ..but i need to achive this using dataset ..please help me if possible ...