C# 如何在Windows phone中从Webservice获取列表?
我有一个密码:C# 如何在Windows phone中从Webservice获取列表?,c#,xml,linq,list,service,C#,Xml,Linq,List,Service,我有一个密码: List<Songs> song; ServiceBaiHat.MywebserviceSoapClient service = new ServiceBaiHat.MywebserviceSoapClient(); service.getListCatalogAsync(); service.getListCatalogCompleted+=service_getListCatalogCompleted; private void service_getLi
List<Songs> song;
ServiceBaiHat.MywebserviceSoapClient service = new ServiceBaiHat.MywebserviceSoapClient();
service.getListCatalogAsync();
service.getListCatalogCompleted+=service_getListCatalogCompleted;
private void service_getListCatalogCompleted(object sender, ServiceBaiHat.getListCatalogCompletedEventArgs e)
{
if (e.Result != null)
{
XElement element = XElement.Parse(e.Result.ToString());
listbaihat = (from p in element.Descendants("songs")
select new Songs
{
name = (string)p.Element("name"),
link = (string)p.Element("link"),
album = (string)p.Element("album")
}).ToList<Songs>();
}
}
列表歌曲;
ServiceBaiHat.MywebserviceSoapClient服务=新的ServiceBaiHat.MywebserviceSoapClient();
service.getListCatalogAsync();
service.getListCatalogCompleted+=服务\u getListCatalogCompleted;
私有无效服务\u getListCatalogCompleted(对象发送方,ServiceBaiHat.getListCatalogCompletedEventArgs e)
{
如果(例如,结果!=null)
{
XElement元素=XElement.Parse(例如,Result.ToString());
listbaihat=(来自element.substands(“歌曲”)中的p)
选择新歌
{
名称=(字符串)p.Element(“名称”),
link=(字符串)p.Element(“link”),
相册=(字符串)p.Element(“相册”)
}).ToList();
}
}
现在,为什么element.subjections(“songs”)出现错误?您可以发布XML吗?我不明白为什么歌曲类型被称为
songs
(复数),而列表被称为song
(单数)listbaihat
不包含变量定义。。。您是否缺少var
或它是否有类型?如果不知道您遇到的错误,可能是元素为null,也可能是没有“songs”子体。