Reputation: 4451
I have simple application from this tutorial: WCF 4 Getting Started Tutorial
How can I implement some encryption? Something like HTTPS (SSL?).
Example code from tutorial.
static void Main(string[] args)
{
// Step 1 of the address configuration procedure: Create a URI to serve as the base address.
Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/Service");
// Step 2 of the hosting procedure: Create ServiceHost
ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);
try
{
// Step 3 of the hosting procedure: Add a service endpoint.
selfHost.AddServiceEndpoint(
typeof(ICalculator),
new WSHttpBinding(),
"CalculatorService");
// Step 4 of the hosting procedure: Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5 of the hosting procedure: Start (and then stop) the service.
selfHost.Open();
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
selfHost.Abort();
}
}
Upvotes: 4
Views: 3246
Reputation: 730
The easiest way is probably to use transport security. See HTTP Transport Security. It describes how to configure SSL for both self-hosted and IIS-hosted services.
If all you need is encryption, then that's it. If you also want client authentication, then the client should use its own certificate which the service must accept.
Upvotes: 4
Reputation: 882
If you want to have https in you IIS7 web site, you can try this:
Then access your site using http://fullyqnameofyourcomputer:81 If you want to access the WCF Service with basic binding with the secure site, just make sure you add securicty mode (Not None) in you client config.
Upvotes: 1