title: Silverlight fault propagation and UserNamePasswordValidator
body: <p>Scenario is a Silverlight client using Wcf service &amp; custom authentication. To mitigate the 500/200 status code problem (avoid EndPointNotFound exception) I've applied the <a href="http://msdn.microsoft.com/en-us/library/ee844556%28v=vs.95%29.aspx" rel="nofollow noreferrer">SilverLightFaultBehaviour</a>. However, this does not work with <a href="http://msdn.microsoft.com/en-us/library/ms551936(v=vs.90).aspx" rel="nofollow noreferrer">UserNamePasswordValidator</a> - When a FaultException is thrown from Validate(), it is not caught by the SilverLightFaultMessageInspector's implementation of BeforeSendReply.</p>
  
  <p>So far, the only workaround I've found is using the alternative client stack instead ( <code>WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);</code>), 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 ( <a href="https://stackoverflow.com/questions/9382809/silverlight-5-debugging-npctrl-dll-crash">Silverlight 5 - Debugging npctrl.dll crash</a> , <a href="http://communities.vmware.com/thread/394306?tstart=0" rel="nofollow noreferrer">http://communities.vmware.com/thread/394306?tstart=0</a> ). </p>
  
  <p>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):</p>
  
  <pre class="lang-cs prettyprint-override"><code>if (e.Error is MessageSecurityException)
  {
      this.HasLoginFailed.Value = Captions.Login_FailedLogin;
  }
  else
  {
      this.HasLoginFailed.Value = Captions.Login_FailedConnection;
  }
  </code></pre>
  
  <p>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?</p>
  
  <p>my server-side code for usernamepassword reg:</p>
  
  <pre class="lang-cs prettyprint-override"><code>var serviceCredential = host.Description.Behaviors.Find&lt;ServiceCredentials&gt;();
  serviceCredential.UserNameAuthentication.UserNamePasswordValidationMode =
                      UserNamePasswordValidationMode.Custom; 
  serviceCredential.UserNameAuthentication.CustomUserNamePasswordValidator =
                      new MyValidator();
  </code></pre>