How to add https host in wcf?

Jan 10, 2013 at 8:41 PM
Edited Jan 10, 2013 at 8:58 PM

Hi Markus,

Another question regarding wcf part of the CODE framework: how can I create an endpoint that uses https? The AddServiceHostBasicHttp function hard code the uri to use http://, do I need to modify the source code to support that?

And how about using SSL for the Rest host? Do I also need to modify the source to support that?

 

Thank you.

Coordinator
Feb 16, 2013 at 1:15 PM
Hello!

Well, I was in the process of sending a detailed response of how to do this with the basic idea being that you use the static events fired by the ServiceGarden class which allow you to make manual settings and modifications on all hosts and endpoints and so forth. The basic idea there would be that you have to a) change the utilized URL to use https and b) change the security on the binding to use Transport security. So that is certainly doable.

However, I then decided that this is a pretty useful standard feature. Plus, we are in the final phases of overhauling both the server-side and client-side infrastructure for services. So I simply decided to add an optional useHttps parameter to all methods related to service hosting and service calling. This will ship in the next version, which should be released within a few days. In that version, you can now host services like so:

host.AddServiceHostBasicHttp(typeof(TestService)); // HTTP
host.AddServiceHostBasicHttp(typeof(TestService), useHttps: true); // HTTPS
host.AddServiceHostWsHttp(typeof(TestService)); // HTTP
host.AddServiceHostWsHttp(typeof(TestService), useHttps: true); // HTTPS
host.AddServiceHostRestJson(typeof(TestService)); // HTTP
host.AddServiceHostRestJson(typeof(TestService), useHttps: true); // HTTPS
host.AddServiceHostRestXml(typeof(TestService)); // HTTP
host.AddServiceHostRestXml(typeof(TestService), useHttps: true); // HTTPS

The equivalent works for calling services using the ServiceClient class.

Note that you still need to make sure you have HTTPS certs configured properly on your server, which is an admin task and has as such nothing to do with CODE Framework. But if the cert is not configured properly, you will get an error message stating the certificate error.


Hope this helps!

Markus
Coordinator
Feb 19, 2013 at 3:07 PM
FYI: The version that includes these features has now been released and is available in the download section.
Feb 20, 2013 at 7:20 PM
Great news, Thanks Markus!

I was using the raised events to change http to https, but I found I need to re-arrange the source code a bit so that the host was not created before I change the protocol. With the new feature, it's supported out of the box.