1

I have a WCF service that implements the 'Custom-Username-Password-Validator'.

The service itself checks the username+password against a local file,

and if there is no match - it throws a FaultException with a message.

.

When I use the service synchronously it works fine.

When I go to work with it ASYNC, I have a problem.

If I pass the wrong 'Username+Password' credentials - and open the client,

instead of returning immediatly from the service going into my 'Channel_Faulted()' method,

the client thread simply waits until the Timeout triggers,

and then I get a 'TimeoutException'.

try
{
    client = new MyServiceClient("WSDualHttpBinding_IMyervice");
    client.ClientCredentials.UserName.UserName = "username";
    client.ClientCredentials.UserName.Password = "bad password";
    client.ChannelFactory.Faulted += new EventHandler(ChannelFactory_Faulted);
    client.Open();   // This hangs for 01:00:00 minute

    // Doesn't reach here
    client.DoSomethingCompleted += new EventHandler<DoSomethingEventArgs(client_DoSomethingCompleted);
    client.DoSomethingAsync(param);
}
catch (Exception ex)
{
    // Enters here with a 'TimeoutException' exception
}

why does the client not trigger the 'Faulted' method I have ?

Why does it wait for a response from the service even though the service through a 'FaultException' during the 'Validate' method of the 'CustomUserNameValidator' ?

John Miner
  • 893
  • 1
  • 15
  • 32

2 Answers2

2

Sure, the code you are using appears to be missing 3 lines after your code line: client.ChannelFactory.Faulted += new EventHandler(ChannelFactory_Faulted);

But again, I'm taking a shot in the dark since I've not made use of this option yet.

var local = client.ChannelFactory.CreateChannel();

((IClientChannel)local).Faulted += ChannelFaulted;

local.Open();

Better yet, the open method doesn't appear to be necessary according to the sample provide here: ChannelFactory

bluelightning1
  • 279
  • 2
  • 6
0

I personally have not used the ChannelFactory.Faulted event handler however, here is a post for your consideration: creating-wcf-channelfactory

Community
  • 1
  • 1
bluelightning1
  • 279
  • 2
  • 6
  • I don't have any problem with hooking up the 'Faulted' event. The problem is - that instead of being fired - it isn't fired and a timeout occurs. Please notice that this happens only if I throw a 'FaultException' during the 'username+password custom validator'. If I throw a 'FaultException' during one of the service's operations - everything works fine, and the 'Faulted' event is raised... – John Miner Jul 18 '12 at 18:23