WCF Client with HTTPS enabled and Authentication

Following code sample shows how WCF client can be used with WCF service running on HTTPS and secure with authentication.

        // Create the binding.
        WSHttpBinding myBinding = new WSHttpBinding();
        myBinding.Security.Mode = SecurityMode.Transport;
        myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

        // Create the endpoint address.
        EndpointAddress ea = new  EndpointAddress("https://www.mywcfservice.com/testwcf.svc");

        // Create the client.
        TestServiceClient cc =   new TestServiceClient(myBinding, ea);
        // The client must provide a user name and password.
        cc.ClientCredentials.UserName.UserName = "uname";
        cc.ClientCredentials.UserName.Password = "pwd";
            // Begin using the client.


            // Close the client.
        catch (Exception ex)



Popular posts from this blog

CSS text-overflow ellipsis in the beginning of the the text - Left Ellipsis using CSS in a Flex box

Selenium With .Net

Handling Exit Event of Console Application in C#