Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing Self Hosting: WCF vs HttpListener

I've been looking into the possibility of using ASP.NET Web API and SignalR in a self-hosted application, and I noticed that the ASP.NET Web API self-hosted implementation uses WCF, and the SignalR self-hosted implementation uses System.Net.HttpListener. This makes it a little harder to come up with a combined self-hosting solution, but it does get me wondering why the different project teams would use different approaches.

What are the advantages and disadvantages of each approach? Is there any particular reason why SignalR could not use WCF self-hosting, or Web API could not use HttpListener?

EDIT: I understand that Web API self-hosting provides a more complete stack than SignalR, my question is more about why you would choose a WCF implementation over System.Net.HttpListener when implementing your own self-hosting solution.

like image 596
John Jeffery Avatar asked Dec 20 '22 16:12

John Jeffery


2 Answers

Web API self host provides entire HTTP stack so it's much much richer than System.Net.HttpListener.

SignalR uses that to purely open a communication window for its own purposes. So yeah for now, you need to run them in parallel on different ports.

In the future, with OWIN, you will have everything under one roof.


EDIT: there was actually an issue similar to yours raised on SignalR github, and the answer was pretty much what I just said - https://github.com/SignalR/SignalR/issues/277

like image 127
Filip W Avatar answered Dec 27 '22 07:12

Filip W


Just so we are on the same page, The WCF Self-host that Web API Self host uses, does use HttpListener under the covers. However, I think I may have found a major downside to the WCF Self-host.

I have not confirmed this yet, but it seems that when you use Web API Self Host, the base address you provide is not translated directly into a HttpListener prefix. It seems like WCF translates the base address and wildcards the host.

This means that the WCF self-host will respond to any host on the specified port. This means that you cannot run a Web API Self hosted service side by side with IIS on the same port using a different host name.

This might be the reason that SignalR decided to scrap the WCF Self-Host and use HTTPListener directly.

like image 43
Darrel Miller Avatar answered Dec 27 '22 07:12

Darrel Miller