我需要在我的Windows手机应用中使用java网络服务,但我不知道确切的程序。但我尝试了以下代码,但它无法正常工作,请告诉我确切的程序或样本。
ObservableCollection<Class1> p = new ObservableCollection<Class1>();
public Antocids()
{
InitializeComponent();
listBox1.DataContext=p;
ServiceReference3.ProductsClient client = new ServiceReference3.ProductsClient();
client.getProdDetailsCompleted += new EventHandler<ServiceReference3.getProdDetailsCompletedEventArgs>(client_getProdDetailsCompleted);
client.getProdDetailsAsync();
}
private void client_getProdDetailsCompleted(object sender, ServiceReference3.getProdDetailsCompletedEventArgs e)
{
p.Clear(); // assuming you want to clear the data each time you get a new result
foreach(var result in e.Result)
p.Add(result)
}
//and this is my class
public class Class1
{
public string name { get; set; }
}
答案 0 :(得分:0)
e.Result可能是“对象”类型。在进行foreach循环之前,尝试将其转换为您期望的类型。
我不知道你期望什么类型,但如果它是一个字符串数组,那么就像:
var myCollection = e.Result as string[];
foreach(var result in myCollection)