We are facing one problem with DownloadStringCompleted method always returning same result in windows phone 7?
First binding the pending requests through service.showing that requuest in listbox placed two buttons.when click on that calling accept service that service update the table.
again while calling the pending request service showing previous result.why please tell me…
Code:
private void getpendingrequests()
{
WebClient wcgetfriends = new WebClient();
wcgetfriends.DownloadStringAsync(
new Uri("http://{ipaddress}/Network/Reccords/GetFriends?userid=" + userId));
wcgetfriends.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(
wcgetfriends_DownloadStringCompleted);
}
void wcgetfriends_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{
String resultgetfriends = null, responseCode = null;
using (var reader = new StringReader(e.Result))
{
resultgetfriends = reader.ReadToEnd();
}
XmlReader xmlDoc = XmlReader.Create(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(resultgetfriends)));
while (xmlDoc.Read())
{
if (xmlDoc.NodeType == XmlNodeType.Element)
{
if (xmlDoc.Name.Equals("ResponseCode"))
{
responseCode = xmlDoc.ReadInnerXml();
}
}
}
if (Convert.ToInt32(responseCode) == 200)
{
string result1 = e.Result.ToString();
XDocument xmlDocu = XDocument.Load(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(result1)));
interestrates = (from rts in xmlDocu.Descendants("Friend")
select new SampleCheckedData
{
Id = (string)rts.Element("userid"),
Name = (string)rts.Element("name"),
Icon = (string)rts.Element("imageurl"),
}).ToObservableCollection<SampleCheckedData>();
this.lstFriendRequuest.ItemsSource = interestrates;
}
if (Convert.ToInt32(responseCode) == 201)
{
MessageBox.Show("UserId is not type of integer");
}
if (Convert.ToInt32(responseCode) == 202)
{
MessageBox.Show("User not exists");
}
if (Convert.ToInt32(responseCode) == 203)
{
MessageBox.Show("No Pending Requests");
}
}
private void requestaccept()
{
WebClient wcacceptrequest = new WebClient();
wcacceptrequest.DownloadStringAsync(
new Uri("http://{ipaddress}/Network/Reccords/FriendRequestAcceptance?userid=" + userId + "&frienduserid=" + _id + "&acceptid=" + 1));
wcacceptrequest.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(
wcacceptrequest_DownloadStringCompleted);
Image b = sender as Image;
var res = interestrates.Where(a => a.Id.Equals(((System.Windows.FrameworkElement)(e.OriginalSource)).Tag)).ToList();
if (res.Count == 1)
interestrates.Remove(res.First());
}
void wcacceptrequest_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{
String resultaccept = null, responseCode = null;
using (var reader = new StringReader(e.Result))
{
resultaccept = reader.ReadToEnd();
}
XmlReader xmlDoc = XmlReader.Create(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(resultaccept)));
while (xmlDoc.Read())
{
if (xmlDoc.NodeType == XmlNodeType.Element)
{
if (xmlDoc.Name.Equals("ResponseCode"))
{
responseCode = xmlDoc.ReadInnerXml();
}
}
}
if (Convert.ToInt32(responseCode) == 200)
{
lstFriendRequuest.ItemsSource = "";
interestrates = new ObservableCollection<SampleCheckedData>();
bindGetFriends();
}
if (Convert.ToInt32(responseCode) == 201)
{
MessageBox.Show("UserId is not type of integer");
}
if (Convert.ToInt32(responseCode) == 202)
{
MessageBox.Show("Friend Id not type of integer");
}
if (Convert.ToInt32(responseCode) == 203)
{
MessageBox.Show("Accept id not type of integer");
}
}
please tell me why in bindfriends method getting previous result……
This is almost certainly being caused by caching either within the phone or within some network proxy.
There are several things you can try to do in order to prevent caching – if you want to always disable the caching then one of the quickest is to add a unique number to the end of your GET request – e.g.
There are other similar questions and answers at: