Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Seems a bit strange, but the solution was to create a separate class library and make reference to its DLL in my WCF service.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IdentityModel.Selectors; using System.IdentityModel.Tokens; using System.ServiceModel; /// &lt;summary&gt; /// Summary description for CustomUsernamePasswordValidator /// &lt;/summary&gt; namespace CustomValidator { public class CustomUserNameValidator : UserNamePasswordValidator { public override void Validate(string userName, string password) { if (null == userName || null == password) { throw new ArgumentNullException(); } if (!AuthenticateUser(userName, password)) throw new SecurityTokenValidationException("Invalid Credentials"); else { // do nothing - they're good } } public bool AuthenticateUser(string userName, string password) { if (userName != "userbill" || password != "passwordbill") { return false; } else { return true; } } } } </code></pre> <p>I then made added a reference to System.IdentityModel and System.ServiceModel. </p> <p>The serviceCredentials section for the WCF service is now changed to this:</p> <pre><code>&lt;serviceCredentials&gt; &lt;!-- Use our own custom validation --&gt; &lt;userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="CustomValidator.CustomUserNameValidator, CustomValidator"/&gt; &lt;/serviceCredentials&gt; </code></pre> <p>Hope that helps someone.</p> <p>I tried this with invalid credentials, and was expecting to see my "Invalid Credentials" message. Instead I'm getting "At least one security token in the message could not be validated."</p> <p>Other than that this thing is finally up and running!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload