wcf数据服务绑定组合框

时间:2011-07-22 16:19:15

标签: wcf silverlight data-binding service combobox

我有一个使用silvelight和wcf数据服务的应用程序。 我想用我的专栏'City'

的值填充comboBox

有人能给我正确的方法吗,因为我的函数因System.InvalidOperationException而失败!

public void GetCities(System.Windows.Controls.ComboBox cmbCity)
    {

        DataServiceQuery<String> userQuery = (DataServiceQuery<String>)proxy.CreateQuery<String>("GetCity");
                    try
        {
            userQuery.BeginExecute(
             (result) =>
             {
                 var userlist = new DataServiceCollection<string>(userQuery.EndExecute(result));

                 cmbCity.ItemsSource = userlist.ToList(); 

             }, null);

                       }
        catch (DataServiceQueryException ex)
        {
            throw ex;
        }
    }

在我的WCF数据服务中:

 [WebGet]
public IQueryable<String> GetCity()
{
   return Usager.GetCity();
}

在我的edmx项目中,我有这个:

public static IQueryable<String> GetCity()
    {
        try
        {
            DataBaseEntities scv = new DataBaseEntities();
            return (from user in scv.Usager
                   select user.City).Distinct();


        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

0 个答案:

没有答案