我正在为WCF ChannelFactory Manager写一些代码。我的问题来自事件“ ChannelFactory.Faulted”:两个参数(“对象发送者”和“ EventArgs args”)都不包含有关原始功能的信息,如何在自定义故障处理程序中获取ChannelFactory故障详细信息?
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 ");
}
感谢您的关注。
最佳答案
我对ILSpy进行了简要介绍,并且ChannelFactory
从CommunicationObject
派生,当在Open
/ BeginOpen
期间引发异常时,它可以转换为故障状态。因此,尝试/捕获Open
至少会捕获某些可能的错误。不知道通道工厂是否还有其他地方可以进入故障状态。注意,Faulted
事件处理程序在finally块中调用,这意味着在捕获异常之前调用了它。
关于c# - 如何在ChannelFactory <TChannel> .Fault中获取故障详细信息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8469654/