AppSelfHostBase and HTTPS

(Sorry, if there is an obvious answer here, I cant find it. Up till now all my services have been HTTPS in Azure hosts, and self-hosted HTTP services for testing. So I’ve not yet learned how to create self-hosted HTTPS services).

I want to provide a service derived from AppSelfHostBase for testing (hosted in console app) that is configured for both http://localhost:4455 and https://localhost:4455.

How do you do that? (preferably in code or config, command line stuff not preferred)

Same as for a normal HttpListener, found a link on StackOverflow: http://stackoverflow.com/a/11457719/85785

Just saw you wanted to use multiple prefixes, there’s no API available for that.

Yep, read all those.

Looking for a way to do it in code or config.

Doubt it could be done in code other than calling an external process, there’s an example of using Process.Start in HttpListenerBase

OK, thanks

so if I want the SS service to run on both HTTP and HTTPS I would need to call Start() twice right?

i.e.

new MySelfAppHost()
    .Init()
    .Start("http://localhost:4455");
    .Start("https://localhost:4456");

Or do I need two instances of MySelfAppHost ??

No neither of those are going to work, there can only by 1 AppHost and Start() can’t be called twice.

I’m looking at adding support for it now.

OK, what could I do in the meantime?

Goal is to host both HTTP and HTTPS endpoints for same service in same process.

It’s not supported.

You can try subclassing a AppHost then somewhere (e.g. overriding Start()) you can initialize the Listener than add a prefix, e.g:

Listener = new System.Net.HttpListener();
Listener.Prefixes.Add("https://*:4456/");
base.Start(urlBase, Listen);

It looks like this may work, but I’d wait for an updated build that supports multiple prefixes.

I think I’ll wait then for a new release. Thanks for the guidance.

FYI Latest v4.0.43 on MyGet now has an overload that support an IEnumerable of prefixes.

1 Like