所以,我有一个非常简单的 WCF 客户端-服务器应用程序。问题是,该服务从客户端获取消息,并且它还接收待处理的消息请求。但是,它不会向客户端返回消息。相反,它显示了这部分: Pending messages does not contain key {id}尽管 id 很好
private Dictionary<int, List<Message>> pendingMessages =
new Dictionary<int, List<Message>>();
public IEnumerable<Message> GetMessages(int id)
{
Console.WriteLine($"New request from {id}");
List<Message> messages;
if (!pendingMessages.ContainsKey(id))
{
Console.WriteLine($"Pending messages does not contain key {id} ");
return null;
}
messages = pendingMessages[id].ToList();
pendingMessages[id].Clear();
foreach (var msg in messages)
{
Console.WriteLine($"Returned message: ${msg.From}=>{msg.To}:{msg.Body}");
}
return messages;
}
public void SendMessage(Message msg)
{
if (!pendingMessages.ContainsKey(msg.To))
{
pendingMessages.Add(msg.To,new List<Message>());
}
pendingMessages[msg.To].Add(msg);
Console.WriteLine($"{msg.From}=>{msg.To}: {msg.Body}");
}