0
我正在使用實體框架和WCF的組合爲客戶端提供數據。但由於某些原因,客戶端掛斷(僅當結果是一個非空列表),然後調用一個簡單的服務器功能:客戶端掛斷,然後從服務器獲取非空列表
public List<CardSet> GetCollactions(string
{
try
{
if (db.Users.Any(x => x.username == username))
{
User requestingUser = db.Users.FirstOrDefault(x => x.username == username);
List<CardSet> result = requestingUser.Collections;
if (result != null)
return result;
}
}
catch (Exception e)
{
db.Errors.Add(new Error() { exception = e.Message, innerException = e.InnerException.Message, source = "GetCollection for user '" + username + "'", time = DateTime.Now });
db.SaveChanges();
}
return new List<CardSet>();
}
在完美地執行功能的服務器,數據庫的結果是正確的。我打電話給客戶端的功能是這樣的:
List<CardSet> collections = client.GetCollactions(username).ToList();
foreach (CardSet collection in collections)
{
CollectionList.Items.Add(collection.name);
}
編輯:客戶端是一個WPF表單。
您的解決方案固定的客戶端,但我我仍然沒有收到來自服務器的數據。我發現一個帖子與我的問題完全相同,他們通過添加Configuration.ProxyCreationEnabled = false來修復它。到EF。但是這對我不起作用,因爲那樣我會得到一個nullreferenceexception –
圍繞使try/catch塊中的網絡調用的代碼環繞,並查看異常的輸出(如果有可能被拋出)。有時我發現我的網絡電話不能正常工作,因爲URL格式錯誤或發送到服務器的數據格式不正確 – Pazuzu156
它被try catch包圍,但不通過錯誤 –