Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF application start event

Tags:

wcf

What is the best way to get notified when a WCF service is first started?

Is there something similar to the Application_Start method in the Global.asax for an ASP.NET application?

like image 315
user89166 Avatar asked Apr 11 '09 00:04

user89166


People also ask

What are 3 basic WCF configurations required for hosting a WCF service?

There are three types of hosting environments for WCF services: IIS, WAS, and self-hosting. The term “self-hosting” refers to any application that provides its own code to initialize the hosting environment. This includes console, Windows Forms, WPF, and managed Windows services.

How do I start WCF?

To open WCF Test Client, open Developer Command Prompt for Visual Studio and execute WcfTestClient.exe. Select Add Service from the File menu. Type http://localhost:8080/hello into the address box and click OK. Make sure the service is running or else this step fails.

How to check WCF Logs?

Viewing Event Logs. Event logging is enabled automatically by default, and there is no mechanism to disable it. Events logged by WCF can be viewed using the Event Viewer. To launch this tool, click Start, click Control Panel, double-click Administrative Tools, and then double-click Event Viewer.

What is ServiceHost C#?

The ServiceHost class creates a ServiceDescription from the service type and configuration information and then uses that description to create ChannelDispatcher objects for each endpoint in the description.


2 Answers

Since it's just a class, you can use a static constructor which will be called the first time the Type is used.

public Service : IContract {     public Service(){ // regular constructor }     static Service(){ // Only called first time it's used. } } 
like image 159
Paul Alexander Avatar answered Oct 08 '22 19:10

Paul Alexander


Well, that might be a bit tricky since the preferred way of calling WCF services is on a "per-call" basis, e.g. you don't really have anything that's "started" and then just hangs around, really.

If you're hosting your service in IIS or WAS, it's even "on-demand loading" of your service host - when a message arrives, the host is instantiated and handles the request.

If you self-host, you either have a console or Winforms app - so you could hook into there to know when they start. If you have a Windows service to host your service host, you most likely override the OnStart and OnStop methods on the ServiceBase class --> hook into there.

The question is more: what exactly are you trying to accomplish? Just logging or something like that, or do you want to have something built up in memory to stick around??

Marc

like image 45
marc_s Avatar answered Oct 08 '22 18:10

marc_s