SSL加密,我從這個教程簡單的應用:WCF 4 Getting Started Tutorial如何使用WCF中
我怎麼能實現一些加密?像HTTPS(SSL?)。
來自教程的示例代碼。
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();
}
}
你是如何託管的WCF服務 - 使用WCF內置的TCP或HTTP綁定,或通過類似IIS? – Rup 2011-05-17 08:50:52
這就像本教程。 – Ichibann 2011-05-17 08:55:48
您應該首先了解您的服務使用哪種配置,並且能夠在您的問題中對其進行描述。爲什麼我們應該閱讀整個教程? – 2011-05-17 09:24:31