I need to run some methods before the first call of a wcf service, where do i put those methods? Where is the startup method of a WCF Service?
Obs1: my WCF Service will run on a IIS6. Obs2: i'm using .net framework 4.0.
Press Ctrl + F5 to run the service. Open WCF Test Client. To open WCF Test Client, open Developer Command Prompt for Visual Studio and execute WcfTestClient.exe.
webserver.exe is located under your . NET framework installation directory (C:\WINDOWS\Microsoft.NET\Framework\v2. 0.50727 or C:\Program Files\Common Files\Microsoft Shared\DevServer), and it may be called a different name such as webdev.
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.
The Windows service should appear in Services as "WCFWindowsServiceSample". The WCF service can only respond to clients if the Windows service is running. To start the service, right-click it in the SCM and select "Start", or type net start WCFWindowsServiceSample at the command prompt.
One way to do this is to self host your WCF services (as in not in IIS). That way you can run whatever code you want to before spinning up the services.
Another way is to add a static method call in the constructor of each service behavior implementation. That static method call would do a check to make sure that the initialization had been performed. Just make sure to deal with multi-threaded concurrency during this call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With