从Silverlight 2.0控件到通过MyWebServiceNameEventArgs返回的WebService的调用未返回包含List<>聚集。例如,我有一个Person类,它有一个List和List。当我跟踪呼叫时,我看到该人员列表已正确填充。但是,当它通过MyWebServiceNameEventArgs到达时,列表为空。正确返回FirstName,DOB等简单类型。
我是否需要做一些事情才能返回封闭的聚合?
这是我的代码:
private void btnGetPerson_Click(object sender, RoutedEventArgs e)
{
var proxy = new TutorWCFServicesClient();
proxy.GetPersonWithPersonKeyOfCompleted += new EventHandler<GetPersonWithPersonKeyOfCompletedEventArgs>(proxy_GetPersonWithPersonKeyOfCompleted);
var perID = 29; // testing
proxy.GetPersonWithPersonKeyOfAsync(perID);
}
void proxy_GetPersonWithPersonKeyOfCompleted(object sender, GetPersonWithPersonKeyOfCompletedEventArgs e)
{
var per = e.Result;
if (per != null)
{
FirstName.Text = per.FirstName;
LastName.Text = per.LastName;
if (per.Phones != null)
{
var hPhone = (from phone in per.Phones where phone.PhoneType.ToLower() == "home" select phone).FirstOrDefault();
var cPhone = (from phone in per.Phones where phone.PhoneType.ToLower() == "cell" select phone).FirstOrDefault();
var wPhone = (from phone in per.Phones where phone.PhoneType.ToLower() == "work" select phone).FirstOrDefault();
if (hPhone != null)
{
PhoneHome.Text = string.Format("({0}) {1}-{2}", hPhone.AreaCode, hPhone.Exchange, hPhone.Number);
}
if (cPhone != null)
{
PhoneCell.Text = string.Format("({0}) {1}-{2}", cPhone.AreaCode, cPhone.Exchange, cPhone.Number);
}
if (wPhone != null)
{
PhoneSchool.Text = string.Format("({0}) {1}-{2}", wPhone.AreaCode, wPhone.Exchange, wPhone.Number);
}
}
}
else
{
FirstName.Text = "Not Found";
}
}
答案 0 :(得分:1)
哑巴错误,我忘了刷新Silverlight应用程序中的ServiceReference。