我在Silverlight 4中工作并使用用于更新客户端的异步模式实现Polling Duplex服务。
// interface for messages back to client
[OperationContract(IsOneWay = true, AsyncPattern=true)]
IAsyncResult BeginSendMessage(byte[] MessageData, AsyncCallback callback, object State);
void EndSendMessage(IAsyncResult result);
我使用我定义的RequestState对象回调客户端,以跟踪我发送给哪个连接的客户端。
AsyncCallback callback = new AsyncCallback(this.MessageSent);
RequestState state = new RequestState { ConnectionNo = connectionno};
client.BeginSendMessage(MessageData, callback, state);
我没有看到使用回调中返回的IAsyncResult参数检查错误的方法。
所以我的问题是,如何判断消息是否无法发送?
答案 0 :(得分:0)
由于这篇文章Is there a way to get error feedback on asynchronous WCF calls?中的帮助,我找到了自己问题的答案:)
当回调返回时,我使用在状态对象中传递的ConnectionNo再次在连接列表中找到连接。
然后我打电话给
try
{
//This is the method that is defined in my ServiceContract to complete the AsyncPattern
client.EndSendMessage(asyncresult);
}
catch
{
//code here to notify the server that there was an error sending the message
}