How to host a WebAPI2 console app in production? - api

I was reading this article in looking for differences between creating an API using WebAPI and MVC and came across this statement:
In simple load testing on my local machine, I’ve found that Web API
endpoints hosted in console apps are nearly 50% faster than both
ASP.NET controller actions and Web API endpoints hosted within MVC
projects.
As such, I'm interested in how this would take shape in a production environment.
Obviously I'm looking for performance, so I looked into OWIN and self-hosting. However I'm not clear on if this offers the same efficiency as the console app discussed above.
Can someone please explain the proposal of hosting an API console application for consumption in a production environment - i.e. how would you connect a URL to the console app, etc.?
Thanks.

My understanding is self hosted OWIN apps can be run within any kind of app domain e.g console, windows forms, windows service, AWS EC2, Azure Worker Role etc. The application you should run it in is dependent upon the hosting environment you choose, there are lots of options.

Related

Hosted service in ASP.NET Core vs Worker Service

For background process listening to a service bus topic, what would be the considerations for choosing between running a hosted service in ASP.NET core VS creating a worker service?
I'm seeing several options from the internet and I'm wondering which scenarios would make one go for each of these options:
Running API & Worker service separately
Running API with hosted service
Running worker service with API inside (not for us)
Our system will have an ASP.NET Core API as well, so I'm wondering whether to add a hosted service to this API or to separate the application as a worker service.
We also want to run this in container and deploy it in Azure container app (if that makes a difference to the considerations)
I saw someone mentioned if health check is needed for the background process then it's better to go with ASP.NET with hosted service implementation. But then I found this lib https://github.com/bruceharrison1984/TinyHealthCheck which seems to add health check functionality to worker service
The API and the worker should be separated. You can then scale the two separately. Especially if you plan to deploy the worker on Azure Container App, you can scale automatically the worker depending on the message number on the bus using KEDA. When no message is in the queue it will automatically scale down to 0 !
Your API in the other hand should be always up.
To create a worker you should consider using the generic host of .Net.
In my opinion, this is related with the relationship with the web api and the worker service.
If this worker service is just used for this asp.net core web api, I suggest you could choose 2 or 3.
If this work service is also used for other web api or else, I suggest you should run API & Worker service separately.
From the comments you have added I can see that the API and the worker service are separate and that you are deploying using docker. For those reasons I would suggest that you deploy these two things separately in their own containers. I would choose this because it makes each application simpler and easier to maintain. A good place to start is here Background tasks with hosted services in ASP.NET Core. There is a simple dotnet cli template to create the project
dotnet new worker -o [your project name]

Azure Functions - ASP.NET Webforms app deployment

I can't find an example code for publishing ASP.NET Webforms websites to Azure Functions. Months ago I tried to replicate the C# example but I ended up with only being able to use the precompiled batch function type.
I want to publish VB.NET web apps - any framework version, using Web Deploy...
Here are some important concepts you should know about Azure Web App and Azure Function:
Azure Web App:
Azure Web App is a sand box. The only way an Azure web app can be accessed via the internet is through the only two already-exposed HTTP (80) and HTTPS (443) TCP ports.
For Nodejs App deployed to Azure, Azure will create a named pipe for your server to listen, and pass the request from 443 port(as you use https) to the named pipe.
Azure Function:
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. You can write just the code you need for the problem at hand, without worrying about a whole application or the infrastructure to run it. Functions can make development even more productive, and you can use your development language of choice, such as C#, F#, Node.js, Python or PHP. Pay only for the time your code runs and trust Azure to scale as needed. Azure Functions lets you develop serverless applications on Microsoft Azure.
Api apps and Web apps are pretty much the same deal. Logic Apps and Functions are the same in a sense that they allow you to do something as a response to event or on a schedule, but Functions are a way to run code (or existing app) and Logic Apps are more like a workflow constructor, where you take existing actions and chain them (so no coding, or almost no)
Deploy:
Use ftp to deploy your web form to Azure Function. There will be no problems with the deployment, but the webpage will not display.
Note:
Although Azure Function and Azure Web App are very similar in many cases. But if you choose to deploy web form app, you will still find differences. Even if you can deploy your project to Azure Web App, it won’t display any webpages.

Differences in Hosting WCF services vs Web API - Startup

My organization is transitioning from MS WCF services to Web API services. One big difference I've noticed is in the startup behavior. If a WCF service isn't spun up, it waits to return until it is spun up. However, if a Web API service is not spun up, it returns 500s until it is spun up.
Is there any way to configure the Web API applications or IIS so that it starts up more like a WCF service, in that it doesn't return anything until it's spun up? I've googled extensively but have been unable to find anything addressing this.
As an FYI, app init isn't an option for us right now.
I believe this is configurable via IIS.
See here:
Auto-Start Feature

Azure webforms application insights

Is it possible use Visual Studio 2013 Application Insights with my web forms project?
I have added application insight to my project but cannot get performance metrics to Application Insights portal. My project is running top of Azure web sites.
There's now an Azure Websites Extension that supports perf metrics for azure websites:
http://blogs.msdn.com/b/visualstudioalm/archive/2015/01/07/application-insights-and-azure-websites.aspx
If you have an Azure WebSite and would like to enable Application
Insights follow these steps:
1) Onboard your application to Application Insights from Visual Studio
2013 Update 3 or later and deploy to an Azure WebSite.
Note: If your application onboarded to Application Insights already
ensure you are using the .12 SDK (or later).
2) Enable the Application Insights Extension on the Azure WebSite
blade (not the Application Insight blade) for the website that was
enabled for Application Insights with the .12 or later SDKs
3) Now the extension is enabled execute a few requests against your
web App and navigate to your Application Insights resource blade
As far as I know Application Insights will only work with Web Applications.
Here are the project types supported:
A web service or web application.
Web pages that use JavaScript. A
Windows Phone 8 app.
A Windows Store app.
See this page for further information on the types of projects you can monitor: http://msdn.microsoft.com/en-us/library/dn481095.aspx
Ken's answer is right for the types of apps that application insights supports really well. this includes seamless onboarding/getting started and loads of "automatic" data visible without having to write any new lines of code.
From an SDK "core" perspective we can support other types of apps like WPF and desktop apps. Here are the steps required to setup it up manually and the code required to get metrics, events, traces, etc sent to the application insights service. this should just work if your winform app is running on an azure website too.
Application Insights for WPF Application
At the present time, Application Insights is focused just on web-based applications.
ASP.NET Web Forms
ASP.NET MVC
ASP.NET Web API
ASP.NET Core
WCF
JavaScript
and some alternative platforms / languages (PHP, Ruby, Java).
Azure App Service (formerly Web Sites) does not support Performance Counters (CPU percentage, Disc read/write operations, Available Memory etc.).
For clarification: Azure Website Extension just helps you to collect dependencies and some statistics in case your application is running on .NET version < 4.6.

Web Service on Windows Azure?

I am new to Windows Azure and I have a question.
I have:
Web site which deployed to Windows Azure - The web site manage a table (add, edit, delete). I used this guide: Deploying an ASP.NET Web Application to a Windows Azure Web Site and SQL Database
Andorid application & iOS Application (Native Code).
Now, I want the mobile applications to get data (in JSON format) from the web site (and from the DB).
What is the best practice to do that?
I tried to create a Azure (WCF) Service (the project refrenced to the web site project) but I didn't succeded. If this is the way - Is anyone knows a good tutorial to do that?
Is there another option? Maybe from the web site itself?
Thank you very much,
Yuval
If you want to integrate with non-Microsoft technologies I suggest you take a look at the ASP.NET Web API which allows you to build REST services using content negotiation. Content negotiation allows your consumer to specify the format it requires (json, xml, ...).
To host the ASP.NET Web API in a Windows Azure Web Site you should take a look at Carlos' blog, he describes in detail what you need to do to make this work: Creating ASP.NET Web APIs on Azure Web Sites
Have you given ASP.NET Web API a look-see?
http://www.asp.net/web-api