Detecting faults when using ChannelFactory

I'm trying to detect a faulted channel from the client side without any success. I'm using ChannelFactory<>.CreateChannel(), not a generated proxy. I've tried to handle the Faulted event of the ChannelFactory, but it is never raised. The transparent proxy that is returned from the CreateChannel method doesn't have any events defined.

So the question is, how does one detect a faulted (or otherwise broken) channel when using ChannelFactory<>.CreateChannel()?

Thanks.

Bruce Bukovics
Author of .NET 2.0 Interoperability Recipes
http://www.apress.com/book/bookDisplay.html?bID=10116

[612 byte] By [BruceBukovics] at [2007-12-22]
# 1
How about something like this?

ChannelFactory<IFoo> cf = new ChannelFactory<IFoo>();
IFoo c = cf.CreateChannel();
((IChannel)c).Faulted += new EventHandler(Channel_Faulted);

BuddhikedeSilva at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 2
Thank you, that is exactly what I was missing. I tried to cast the channel to ChannelBase but that didn't work. I didn't try IChannel.

Bruce

BruceBukovics at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 3

But how do I find out what exception has occurred? (I want to be able to log exceptions in a central place)

RobertteKaat-IS at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 4
Who said an exception occurred? The Faulted event will fire, for example, if someone calls channel.Abort(). There's not necessarily any associated exception.
BrianMcNamara-MSFT at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 5
Hi. How can I convert

((IChannel)c).Faulted += new EventHandler(Channel_Faulted);

in VB.Net?

I tried ctype(c,IChannel). but it doesn't have any events, just a State property and some methods BeginOpen, BeginClose...

What am I doing wrong?

Thanx

celobateira at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 6

Try something like this:

Code Snippet

Dim cf As ChannelFactory(Of IService1) = New ChannelFactory(Of IService1)()
Dim c As IService1 = cf.CreateChannel()
Dim chnl As Channels.IChannel = CType(c, Channels.IChannel)
AddHandler chnl.Faulted, me.myFaultEvent

DwightGoins at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...

Visual Studio Orcas

Site Classified