2011-10-23 48 views
0

你好,大家好我建立WCF服務,我有兩種方法插入和獲取(必須返回列表)插入法正常工作啓用Silverlight的WCF服務不能返回列表

這是獲得方法:

public List<string> GetUsersList() 
     { 
      csmasterDataContext db = new csmasterDataContext(); 
      List<string> _uList = new List<string>(); 
      _uList = (from d in db.users select d.username).ToList(); 
      return _uList; 
     } 

時我把這種方法是這樣的:

List<string> _UserList = new List<string>(); 

      _UserList = webService.GetUsersListAsync(); 

的Visual Studio提供了錯誤:

Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<string>' 

有沒有人有想法我的問題是什麼? Web服務的

+0

做你檢查我的GetUsersList方法?其返回_uList; –

回答

4

異步調用是異步它沒有返回值......你要這樣稱呼它

webService.GetUsersListAsyncCompleted += 
     new EventHandler<GetUsersListEventArgs> (GetUsersListCompleted); 

webService.GetUsersListAsync(); 

void GetUsersListCompleted(object sender, GetUsersListEventArgs e) 
{ 
    // Set your return here 
    usersList = e.Result; 
} 

檢查thisthis