I've tried to create a self-hosting sample using SSL. For that, I assigned a cert using the following lines of code.
var config = new MyHttpsSelfHostConfiguration("https://localhost:4443");
[...]
config.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "24e2f9c13090f52f378ffcd40172787daa0d930a");
That did not work. But then I bound this certificate using "netsh http add sslcert" and it worked. But after that, it also works, when i commend out the line calling SetCertificate
This is a known issue with the current version. The certificate property on the HttpConfiguration today will trigger the runtime to set the HttpBinding to use Transport security. you can work around it by using a custom self host configuration, and overrid
the OnConfigureBinding() method.
public class MyHttpSelfHostConfiguration : HttpSelfHostConfiguration
{
public MyHttpSelfHostConfiguration(string baseAddress) : base(baseAddress) { }
public MyHttpSelfHostConfiguration(Uri baseAddress) : base(baseAddress) { }
I've tried this before an now one more time - without success.
Do I need any IIS-components for that to work? In my virtual machine, I use for testing web api, I don't have IIS activated. It's a windows 7 pro default-installation...
manfred.stey...
Member
35 Points
57 Posts
SSL and Web-API
Mar 02, 2012 03:01 PM|LINK
Hi,
I've tried to create a self-hosting sample using SSL. For that, I assigned a cert using the following lines of code.
var config = new MyHttpsSelfHostConfiguration("https://localhost:4443");
[...]
config.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "24e2f9c13090f52f378ffcd40172787daa0d930a");
That did not work. But then I bound this certificate using "netsh http add sslcert" and it worked. But after that, it also works, when i commend out the line calling SetCertificate
// config.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "24e2f9c13090f52f378ffcd40172787daa0d930a");
So I'm wondering, what this method is for.
Wishes,
Manfred
Hongmei Ge
Member
26 Points
8 Posts
Microsoft
Re: SSL and Web-API
Mar 03, 2012 12:14 AM|LINK
This is a known issue with the current version. The certificate property on the HttpConfiguration today will trigger the runtime to set the HttpBinding to use Transport security. you can work around it by using a custom self host configuration, and overrid the OnConfigureBinding() method.
public class MyHttpSelfHostConfiguration : HttpSelfHostConfiguration
{
public MyHttpSelfHostConfiguration(string baseAddress) : base(baseAddress) { }
public MyHttpSelfHostConfiguration(Uri baseAddress) : base(baseAddress) { }
protected override BindingParameterCollection OnConfigureBinding(HttpBinding httpBinding)
{
if (BaseAddress.Scheme == Uri.UriSchemeHttps)
{
// we need to use SSL
httpBinding.Security = new HttpBindingSecurity()
{
Mode = HttpBindingSecurityMode.Transport,
};
}
return base.OnConfigureBinding(httpBinding);
}
}
manfred.stey...
Member
35 Points
57 Posts
Re: SSL and Web-API
Mar 03, 2012 10:40 AM|LINK
Hi,
I've tried this before an now one more time - without success.
Do I need any IIS-components for that to work? In my virtual machine, I use for testing web api, I don't have IIS activated. It's a windows 7 pro default-installation...
Wishes,
Manfred