Friday, October 12, 2012

Silverlight fault propagation and UserNamePasswordValidator

Silverlight fault propagation and UserNamePasswordValidator

Scenario is a Silverlight client using Wcf service & custom authentication. To mitigate the 500/200 status code problem (avoid EndPointNotFound exception) I've applied the SilverLightFaultBehaviour. However, this does not work with UserNamePasswordValidator - When a FaultException is thrown from Validate(), it is not caught by the SilverLightFaultMessageInspector's implementation of BeforeSendReply.

So far, the only workaround I've found is using the alternative client stack instead ( WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);), but there are complications with using it which can no longer be ignored as a lot of our clients are on virtual machines, the silverlight client keeps crashing ( Silverlight 5 - Debugging npctrl.dll crash , http://communities.vmware.com/thread/394306?tstart=0 ).

My primary motivation is that I want to be able to distinguish a failed login from a connection error (the following code is from a client-side async callback method, and only works with the Client stack):

if (e.Error is MessageSecurityException) {     this.HasLoginFailed.Value = Captions.Login_FailedLogin; } else {     this.HasLoginFailed.Value = Captions.Login_FailedConnection; } 

Is there any other way of modifying the message sent when throwing a FaultException from UserNamePasswordValidator? Or any conceptually different way of doing custom authentication rather than what I am using which enables me to modify the message status or to keep it 200, or just to be able to distinguish a connection failure from bad credentials?

my server-side code for usernamepassword reg:

var serviceCredential = host.Description.Behaviors.Find<ServiceCredentials>(); serviceCredential.UserNameAuthentication.UserNamePasswordValidationMode =                     UserNamePasswordValidationMode.Custom;  serviceCredential.UserNameAuthentication.CustomUserNamePasswordValidator =                     new MyValidator(); 

Answers & Comments...




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog