我们面临一个问题,DownloadStringCompleted 方法总是在 windows phone 7 中返回相同的结果?
首先通过服务绑定挂起的请求。显示列表框中的请求放置了两个按钮。当单击该调用接受服务时,该服务更新表。再次调用显示先前结果的待处理请求服务。为什么请告诉我...
代码:
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");
}
}
请告诉我为什么在 bindfriends 方法中得到以前的结果......