Communication Between WCF Service and Android Client Overview of REST in WCF Windows Communication Foundation (WCF), part of the.NET Framework, provides the first unified programming model for rapidly building service-oriented applications. Windows Service Hosting − For local system clients, it is best to host WCF service as a window service and this is known as Window Service Hosting. All the versions of Windows support this type of hosting and here, the Service Control Manager can control the process lifecycle of the WCF service. Previous Page Print Page.
-->This topic demonstrates how to enable a Windows Communication Foundation (WCF) service to authenticate a client with a Windows domain username and password. It assumes you have a working, self-hosted WCF service. For an example of creating a basic self-hosted WCF service see, Getting Started Tutorial. This topic assumes the service is configured in code. If you would like to see an example of configuring a similar service using a configuration file, see Message Security User Name.
To configure a service to authenticate its clients using Windows Domain username and passwords use the WSHttpBinding and set its Security.Mode
property to Message
. In addition you must specify an X509 certificate that will be used to encrypt the username and password as they are sent from the client to the service.
On the client, you must prompt the user for the username and password and specify the user’s credentials on the WCF client proxy.
To configure a WCF service to authenticate using Windows domain username and password
Create an instance of the WSHttpBinding, set the security mode of the binding to WSHttpSecurity.Message, set the
ClientCredentialType
of the binding to MessageCredentialType.UserName, and add a service endpoint using the configured binding to the service host as shown in the following code:Specify the server certificate used to encrypt the username and password information sent over the wire. This code should immediately follow the code above. The following example uses the certificate that is created by the setup.bat file from the Message Security User Name sample:
You can use your own certificate, just modify the code to refer to your certificate. For more information about creating and using certificates see Working with Certificates. Make sure the certificate is in the Trusted People certificate store for the Local Machine. You can do this by running mmc.exe and selecting the File, Add/Remove Snap-in... menu item. In the Add or Remove Snap-ins dialog, select the Certificates snap-in and click Add. In the Certificates Snap-in dialog select Computer account. By default the certificate generated from the Message Security User name sample will be located in the Personal/Certificates folder. It will be listed as 'localhost' under the Issued to column in the MMC window. Drag and drop the certificate into the Trusted People folder. This will allow WCF to treat the certificate as a trusted certificate when performing authentication.
To call the service passing username and password
The client application must prompt the user for their username and password. The following code asks the user for username and password:
Warning
This code should not be used in production as the password is displayed while being entered.
Create an instance of the client proxy specifying the client's credentials as shown in the following code: