Automatic initialization of IIS-hosted WCF service - asp.net

I have an ASP.NET web-site and a WCF service which is called from ASP. The problem is, that during the first client request the site loads aufully slow, cause some time-consuming static objects are being created inside the WCF service. Is it possible to call any service method (by doing this the wcf object will be created), when the site gets loaded in IIS? (I know there is a solution for this problem in ASP 4 and IIS 7.5, but i'd like to know what's about IIS6-7). It is something like "user emulation") Maybe i can add some event handlers in global.asax? Any help is appreciated.

A very simple solution is to use wget within a scheduled task in Windows to simply issue a HTTP GET to your service. This will keep your application 'warm' and ticking over.

Related

What is the actual need for IIS in asp.net

Hey guys I just encountered with a bit of confusion while learning ASP.NET MVC. So, please can you explain in simple terms why need to host web application to web server if, as I learned MVC, controller is there to handle requests and responds, that is, why on earth need IIS while there is controller. Yes, you can say this question is quite stupid but I cannot tell them apart Web server and controller thus I need your help.
TL;DR: IIS serves your controllers as callable end-points. IIS is a web server. You can read more about MVC life-cycle on https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/lifecycle-of-an-aspnet-mvc-5-application
About IIS server:what-is-iis-server
Long Story;
IIS: this guy hosts your any application. the application can be MVC, ASP web site. It basically runs a process to listen specific port(s) if there is any request on it. So it stands outer of your served application.
Controller: When IIS(with net core you can serve your application via many web-servers (I personally use kestrel)) handle a request and addresses your application, your MVC pipeline kicks in. It handles the request(this request shaped for the application by IIS already) then, execute routes-handlers-filters. Then finally, your controller can process its method.

Calling WCF service from jsp page

I have created a WCF Service and published it to a Windows Server running IIS. In an asp.net web application, I can add a Service Reference to the WCF Service which exposes its methods which I can call. This all works fine.
I need someone who is running a jsp site to be able to call a method in my WCF Service. How can they do that? (I know absolutely nothing about jsp). Presumably they cannot reference my WCF Service within their application in the same way you can within a .net application.
The web services are totally platform independent. Therefore, someone writing in Java should have no problem calling a web service server, regardless if it was written using WCF or another platform. For example, here, here and here you could find some tutorials on how to build web service clients using java. This java code could be called from JSP pages.
If you want to quickly test your web service from the client side, you could use SoapUI. It's a web service client tool developed in java. I am sure you will find it useful.
Hope I helped!

Consume web service from same web application

I seem to have struck a complete blank and will most likely have a homer moment when someone points me in the right direction.
I have a WCF Web Service which is consumed happily across asp.net, windows phone, windows services, etc, etc. I'm adding a page to the same application in which the service resides, basically a "test" page that the user can go to and it'll do a quick call to the service to see if the server is up.
Now normally, you'd just throw in a Service Reference and bobs your uncle, but for the life of me, I just can't seem to click what I'm supposed to do when I'm accessing the service from within the same application, do I still add a service reference or is there a quicker way to do it?
Thanks!
Try to reference the web service by its name in the code and see if you'll be able to create new object from that web service and then consume in the code, instead of creating a reference.

How to call WCF at a scheduled timings?

I have to export data from a database in the form of flat files. I already have an asp.net website which saves data into the db. I am thinking of creating a WCF webservice project as part of the website solution. This WCF webservice will have methods to export flatfiles. I am also planning to create a console app to call this webservice at scheduled times.
I have the following questions:
Once the website is hosted on IIS along with WCF, can the console app call the WCF or WCF has to be hosted separately?
How to debug the process?
is there any better way of doing it?
Once the website is hosted on IIS along with WCF, can the console app
call the WCF or WCF has to be hosted separately?
The console app can call the WCF web service. It does not have to be hosted separately.
How to debug the process?
Ideally, on your own PC. Easy way to do is to launch the WCF Webservice within one instance of Visual Studio and the Console App on another instance of VS. You can put break points on each of the projects and follow the logic
is there any better way of doing it?
There are many ways to do one thing but yours in this case looks good to me.
Your plan sounds fine to me.
If I were doing this I might create a WCF Service with One Way Operations so that the client app is not waiting for a response until the job is complete.
I might use Powershell and a scheduled task to hit the WCF service, or even use the free Pingdom service to hit the service endpoint at intervals.
To debug locally- if the WCF is it's own project make sure it's set as the startup project in VS, then apply break points, run debug and request the endpoint through the browser or Fiddler.

ASP.NET warmup/initialize

I'm trying to eliminate (or at least minimize) startup/warmup times for my .NET applications. I'm not really sure on how to do this even though it's a common concern.
There's a ton of questions about slow startup of .NET applications. These are easily explained by pool recycles, worker process startup, dynamic compilation of .aspx files, JIT etc. In addition, there are more things that may need to be initialized within the application such as EntityFramework and application caches.
I've found alot of different solutions such as:
ASP.NET Precompilation
IIS 8 Application Initialization (and for IIS 7.5)
Auto-Start ASP.NET Applications
However, I'm not entirely satisfied with any of the solutions above. Furthermore I'm deploying my applications to Azure Websites (in most cases) so I have limited access to the IIS.
I know that there are some custom "warmup scripts" that uses various methods for sending requests to the application (e.g. wget/curl). My idea is to create a "Warmup.aspx" page in each of my ASP.NET applications. Then I have a warmup service that sends an HTTP GET to the Warmup.aspx of each site every ... 5 minutes. This service could be a WorkerRole in Azure or a Windows Service in an on-premise installation. Warmup.aspx will will then do the following:
Send an HTTP GET to each .aspx-file within the application (to
dynamically compile the page)
This could be avoided by precompiling the .aspx pages using aspnet_compiler.exe
Send a query to the database to
initialize EntityFramework
Initialize application caches etc
So, my final question is whether there are better alternatives than my "Warmup.aspx" script? And is it a good approach or do you recommend some other method? I would really like some official method that would handle the above criteria.
Any and all suggestions are welcome, thanks!
Did you try this IIS Auto-Start feature described here ?
https://www.simple-talk.com/blogs/2013/03/05/speeding-up-your-application-with-the-iis-auto-start-feature/
You could have two instances of the site. When you need to deploy a new version, and therefore suffer a startup cycle, remove one instance out of load balancer rotation, deploy and start it, set it in and do the same for instance 2. A rolling deployment.

Resources