ASP.NET Web api, multiple applications under same host name - asp.net

Lets say that I have multiple internal ASP.NET web api applications. i.e.
http://service1.something.com/bob/bill
http://service2.something.com/pete
http://service3.something.com/dancing/dragon
I would like to expose these different services under a common host name
http://something.com/service1/bob/bill
http://something.com/service2/pete
http://something.com/service3/dancing/dragon
The reason I'm thinking of this setup is to allow each service to run a different set of middleware, but give the client a uniform URL structure to use. Each service can then be upgraded indepently of the others.
Ideally this should be using the latest version of ASP.NET and potentially hosted on Service Fabric. It doesn't have to run on the new core stack, the full .NET framework is acceptable.
I've read that the WebListener supports port sharing, so that is something I'm considering.
Suggestions?

Yes, you can do this with ASP.NET applications in Service Fabric:
service 1: http://something.com/service1/bob/bill
service 2: http://something.com/service2/pete
service 3: http://something.com/service3/dancing/dragon
As long as you use a web stack that supports port sharing. On windows, that means using a web stack that uses the http.sys kernel driver. Here are the web hosting options currently available for ASP.NET on Service Fabric:
The WebListener host in ASP.NET Core 1 is based on HttpListener which uses http.sys, so that will work.
Kestrel in ASP.NET Core 1 is not based on http.sys and to my knowledge does not support port sharing, so that won't work.
Katana uses HttpListener so that will also work.

Even in Azure Fabric every service should have different port - port sharing is available for service replicas (statefull) or multiple instances of the same service (stateless).
https://azure.microsoft.com/en-us/documentation/articles/service-fabric-service-manifest-resources/
Common way to have uniform URL structure is to create Api Gateway, which will call other services.
http://microservices.io/patterns/apigateway.html

Related

What is more suitable: A windows service or WCF service?

I am creating a web app. I want to create a listening service (TCP) that listens continuously and updates web page according to that.
A Windows service or a WCF service?
At the end I just want a background service that listens on a socket continuously and update data in database. and when database is updated I will use signal r to show that in my page.
Right now I am trying with WCF but I am wondering if it can be done with Windows service also. And right now this application will work on LAN. But in the future, it can also be in the cloud.
First of all, it is important to understand that a Windows service and a WCF service are not the same.
A Windows service is a specialized executable that runs in the background on Windows.
A WCF service is a specialized piece of code that exposes some functionality through a well-defined endpoint. It does not run on its own, but instead must be hosted by some parent process, like IIS, a desktop application, or even a Windows service.
In thinking about the problem you've described, I suppose the most fundamental question to ask is whether or not you have control over the data that will be received via the TCP connection. WCF is built on the notion of the ABCs (Address, Binding, and Contract), all of which have to match in order to facilitate data exchange between WCF endpoints. For example, if you wish to expose a WCF endpoint via IIS that accepts TCP connections from some remote WCF endpoint, the remote WCF endpoint needs to send data to your IIS-hosted WCF endpoint using the agreed-upon data contract. Absent that, WCF will not work. So, if you cannot define the data contract to be used between WCF endpoints, then you'll need to find another option. An option that will work is to open a TCP listener within a Windows service, process the data as it is received, update your database, and listen for more data.
================================================
By way of example, I work on a project that has a front-end desktop application that communicates with a back-end Windows service. We build both the application and the Windows service, so we have full control over the data exchange between the two processes. At one point in time, we used WCF as the mechanism for data exchange. The Windows service would host a WCF service that exposed a NetNamedPipeBinding, which we later on changed to NetTcpBinding to get around some system administration issues. The application would then create its own endpoint to communicate with the WCF service being hosted within the Windows service.
This worked fine.
As our system got more mature, we needed to start sending more and more information from the Windows service to the application. If I recall correctly, I believe we experimented with streaming within WCF and concluded that the overhead was not something we could tolerate. So, we used WCF to exchange commands and status information between the application and the Windows service, but we simultaneously used a TCP socket connection to stream the data from the Windows service to the application.
This worked fine.
When we got a chance to update the Windows service software, we decided that it would be better to have a single communication mechanism between the Windows service and the application. So, we replaced WCF altogether with a TCP socket connection that uses a homegrown messaging protocol to exchange information in both directions - application to Windows service and Windows service to application.
This works fine and is the approach we've used for a couple of years now.
HTH

HTTP.sys vs Kestrel: Why choose one over the other? Pros Cons?

What is the reason for two separate but similar servers?
What are the differences?
Can I run both in docker?
Do both support same things, like all authentication types?
Kestrel vs HTTP.sys - I've highlighted the fundamental differences below.
(The words are Microsoft's and I've only edited it for brevity and clarity. See the sources linked at the bottom).
Update:
Kestrel previously always required the use of a reverse proxy with edge deployments (exposed to traffic from the Internet) for security reasons. With Kestrel in ASP.Net Core 2.x this is no longer the case. Take a look at the documentation for more information. Kestrel Web Server Documentation
Weblistener was renamed HTTP.sys in ASP.NET Core 2.0
Sources:
Docs.Microsoft.com Web server implementations in ASP.NET Core
Docs.Microsoft.com HTTP.sys web server implementation in ASP.NET Core
HTTP.sys is windows-only HTTP / Web Server for ASP.NET Core that allows you to expose the server directly to the Internet without needing to use IIS. HTTP.sys is built on top of Http.Sys ( the same mature technology that also powers IIS' HTTP Listener) as is as such very feature rich and provides protection against various attacks.
Kestrel on the other hand, is a cross-platform web server for ASP.NET Core that is designed to be run behind a proxy (for example IIS or Nginx) and should not be deployed directly facing the Internet. Kestrel is relatively new and does not have a full complement of defenses against attacks. It's also not as feature rich as HTTP.sys and comes with timeout limits, size limits and concurrent user limits.
In essence, the choice comes down to your web application's Deployment scenario.
HTTP.sys Use Cases :
Kestrel Use Cases :
Following comparison will help you to choose which one is better
The ASP.NET 5 documentation (created by Microsoft on August 25, 2015) found here lists the chart found in the other answer (see page 107 of the bottom right book pages, but page 111 of the PDF): https://media.readthedocs.org/pdf/aspnet/theming/aspnet.pdf
Kestrel in general has better performance, if you used for one of the following below:
Great option if used in conjunction with a reverse proxy for apps exposed to Internet
Internal apps connecting with other internal apps on a private virtual network (not exposed to Internet)
WebListener is more secure, slower, and has more features. It is used in these cases:
Expose app to the Internet but can't use IIS
Require higher security and exposing server directly to Internet.
Additional features: List item, Windows Authentication, Port sharing, HTTPS with SNI, HTTP/2 over TLS (Windows 10), Direct file transmission, Response caching

How to host both asp.net (for SignalR) and WCF (for netTcpBinding) in single web-role and wire them up to the hosting IIS?

How do I host both asp.net (to use SignalR w/ Azure's backplane) and WCF service (for fast binary netTcpBinding) in web-role (extreme budget issues...)?
I suppose both must be self-hosted, but how to wire up each of them to the hosting IIS in the VM (I believe they both reside in the same app-domain)?
(It's a continuation of "Is it possible to host both web/SignalR and WCF w/ netTcpBinding in a single web-role?")
If you're self hosting your apps, you do not use IIS and could go with a Worker Role (VM without IIS).
That would have the applications running in separate processes - hence different app-domains.
You sepcify the listening port of you asp.net application in the OWIN start method - e.g. Microsoft.Owin.Hosting.WebApp.Start("http://localhost:8080")

Is it possible to host both web/SignalR and WCF w/ netTcpBinding in a single web-role?

We have binary WCF service (netTcpBinding) in a web-role and an asp.net website (to take advantage of SignalR over azure's backplane). Due to the extremely low budget, we want to host them both in a web-role (as website doesn't allow non-standard-HTTP(S) ports).
So is it feasible to host them both in a web-role, to keep the SignalR/web-interface capabilities but also use the binary WCF/netTcpBinding pattern?
Edit:
Maybe I should've asked in the first place "How to host both asp.net (for SignalR) and WCF (for netTcpBinding) in single web-role and wire them up to the hosting IIS?"
As long as socket binding does not conflict - I cannot see why that should not be possible.
See here:
What default port does WCF use for nettcp when hosted by IIS?
https://msdn.microsoft.com/en-us/library/ms731810(v=vs.110).aspx

NServicebus Hosted in IIS vs Windows Service

I am hosting a handler inside of a IIS web application. Is this a good solution ? Or Should I Hosting a handler in windows service application ? Which solution is better? What is recommended and what is more performance ?
I use SqlTransport in my configuration.
There are many factors that can effect how you choose to host your endpoint(s). For example
How you want to scale your site / handlers
What permissions can be granted to your web site process
How an IIS reset can effect your handling code
But in general... Host the bus in both the Web Application and a Windows service.
The web application handles incoming http requests, translates those requests to messages and places them on the bus via a Send.
The Windows service takes message off the bus and does the actual handling/business processing.
Some useful links that may guide you to the best solution for you circumstance
Hosting documentation http://docs.particular.net/nservicebus/hosting/ which contains some information on hosting in a web application
Windows Service Hosting http://docs.particular.net/nservicebus/hosting/windows-service
A showcase sample that uses a similar design as i described above http://docs.particular.net/samples/show-case/on-premise/
Web related samples http://docs.particular.net/samples/web/
Implications of Publishing from Web Applications http://docs.particular.net/nservicebus/hosting/publishing-from-web-applications
If you need to send messages from your web application then the only solution is to host NServiceBus in IIS, With IIS you shouldn't be publishing events from IIS.
Take a look here for more details
HTH

Resources