Note that there are some explanatory texts on larger screens.

plurals
  1. POC#: method to add WCF authentication, username + SSL?
    primarykey
    data
    text
    <p>I've written both a WCF client and a remote internet WCF server.</p> <p>The remote WCF server is running WPF hosted in a traditional Windows Service wrapper (i.e. not IIS).</p> <p>Currently, its working perfectly with basic HTTP binding. I'm using Visual Studio 2010 + .NET 4.0 + C#.</p> <p>Can anyone point me in the direction of the right steps to alter my code so that I can add username + SSL authentication?</p> <p><strong>EDIT:</strong></p> <p>At the service end, I've overridden UserNamePasswordValidator as follows:</p> <pre><code>public class CustomUserNameValidator : UserNamePasswordValidator { public override void Validate(string userName, string password) { Console.WriteLine("Got to here"); } } </code></pre> <p>At the service end, I've specified a link to the username validation class:</p> <pre><code> ServiceHost serviceHost = new ServiceHost(typeof(PhiFeedServer.PhiFeed)); // ,baseAddress); const bool passswordAuthentication = true; if (passswordAuthentication) { // These two lines switch on username/password authentication (see custom class "CustomUserNameValidator" in common file PhiFeed.svc.cs) // See http://msdn.microsoft.com/en-us/library/aa354513.aspx serviceHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom; serviceHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new CustomUserNameValidator(); } // Start the service serviceHost.Open(); </code></pre> <p>At the client end:</p> <pre><code> EndpointAddress endpointAddress = new EndpointAddress("http://localhost:20000/PhiFeed?wdsl"); BasicHttpBinding serviceBinding = new BasicHttpBinding(); serviceBinding.ReceiveTimeout = new TimeSpan(0, 0, 120); proxy = new PhiFeedClient(serviceBinding, endpointAddress); proxy.ClientCredentials.UserName.UserName = "myusername"; proxy.ClientCredentials.UserName.Password = "mypassword"; </code></pre> <p>However, when I run everything, it never even calls the username validator - whats going on?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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