【发布时间】:2015-02-12 15:09:16
【问题描述】:
我异步使用 WCF 服务。如果我无法连接到服务或发生异常,它将进入故障状态并将错误写入AsyncCompletedEventArgs 的Error 属性。
我与服务客户端有什么关系?我无法关闭它,因为它会抛出 CommunicationObjectFaultedException。记录错误后我还需要做什么?
这是我的代码:
MyServiceClient serviceClient = new MyServiceClient();
//Close the connection with the Service or log an error
serviceClient.JustAMethod += (object sender, AsyncCompletedEventArgs args) =>
{
if (args.Error != null)
{
//Log error
ErrorHandler.Log(args.Error);
}
else
{
serviceClient.Close();
}
};
//Call the service
serviceClient.JustAMethodAsync();
【问题讨论】:
标签: c# wcf asynchronous