我正在为WCF ChannelFactory Manager编写一些代码。我的问题来自事件“ChannelFactory.Faulted”:两个参数(“对象发送者”和“EventArgs args”)都不包含有关原始fualt的信息,如何在自定义故障处理程序中获取ChannelFactory Fault详细信息?
private ChannelFactory CreateFactoryInstance<T>(string endpointConfigurationName, string endpointAddress)
{
ChannelFactory factory = null;
factory = new ChannelFactory<T>(endpointConfigurationName, new EndpointAddress(endpointAddress));
//Customizing Factory Fault handler
factory.Faulted += FactoryFaulted;
factory.Open();
return factory;
}
private void FactoryFaulted(object sender, EventArgs args)
{
ChannelFactory factory = (ChannelFactory)sender;
factory.Close();
//...
//How can I get more Fault detail, so as to throw a meaningful Exception?
throw new ApplicationException("Failure in ChannelFactory ");
}
感谢您的关注。
答案 0 :(得分:1)
我简要介绍了ILSpy,ChannelFactory
派生自CommunicationObject
,当Open
/ BeginOpen
期间抛出异常时,Open
会转换为故障状态。因此,Faulted
周围的try / catch将至少捕获一些可能的错误。不确定是否有其他地方通道工厂可能进入故障状态。请注意,在finally块中调用{{1}}事件处理程序,这意味着在捕获异常之前调用它。