none
Unable to open its IChannelListener RRS feed

  • Question

  • Hi everyone,

    I'm trying to make a simple WCF application with client authentication.

    I've found this

    But I want it to be progammatical, so, I've done this code :

    private static void Main(string[] args)
            {
                //const string serviceAddress = "http://localhost:27020/AccountAuthenticator";
                var serverPort = 0;
    
                while (true)
                {
                    try
                    {
                        Console.Write("Enter service port : ");
                        serverPort = int.Parse(Console.ReadLine());
                        break;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Invalid server port. Please try again");
                        Console.ReadLine();
                    }
                }
    
                var serviceAddress = string.Format("http://localhost:{0}/AccountAuthenticator", serverPort);
    
                // Create an isntance of service host which manages connection from clients.
                var serviceHost = new ServiceHost(typeof (AuthenticationService), new Uri(serviceAddress));
    
                // Create an instance of ServiceMetadataBehavior class to define what server will behave.
                var serviceMetadataBehavior = new ServiceMetadataBehavior();
                var serviceCredentials = new ServiceCredentials();
                serviceCredentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
                serviceCredentials.UserNameAuthentication.CustomUserNamePasswordValidator = new IdentityValidator();
                
                serviceHost.Description.Behaviors.Add(serviceMetadataBehavior);
                serviceHost.Description.Behaviors.Add(serviceCredentials);
                serviceHost.AddServiceEndpoint(typeof (IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(),
                    "mex");
    
                // Create an instance of BasicHttpBinding with default initialization.
                var wsDualHttpBinding = new WSDualHttpBinding();
                wsDualHttpBinding.Security.Mode = WSDualHttpSecurityMode.Message;
                wsDualHttpBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
    
                serviceHost.AddServiceEndpoint(typeof (IAuthenticationService), wsDualHttpBinding, serviceAddress);
                serviceHost.Open();
    
                Console.WriteLine("Service has started at port {0}. Press enter to terminate", serverPort);
                Console.ReadLine();
            }

    But it gave me an error when I tried to open the service.

    The ChannelDispatcher at 'http://localhost:27515/AccountAuthenticator' with contract(s) '"IAuthenticationService"' is unable to open its IChannelListener.

    Can anyone help me , please ?

    Thank you.

    Sunday, December 20, 2015 10:19 AM

Answers

  • Hi Linh Nguyen Duy,

    According to this case, as far as I know, when we used username and password, we need

    to use the certificate to encrypt  the username and password. So, we need to set the

    certificate with server-side.

    We need to create a certificate, then add the following code to server-side.

    serviceHost.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "localhost");
    
    

    For more information, please refer to the following articles:

    1.unable to open its IChannelListener

    2.How to: Authenticate with a User Name and Password

    3.How to: Create Temporary Certificates for Use During Development

    Best Regards,

    Wanjun Dong


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.


    Monday, December 21, 2015 7:36 AM
    Moderator