Do something when my WCF service starts

I want to do something right after starting the WCF service. How can I do that?

In fact, I have to update some variable of my service every 10 minutes. So I put the update code in the stream. But I don’t know how to start this thread when the service starts (is there something like the Form_Load event in WCF services?)

+5
source share
4 answers

Typically, there are no parts of your WCF service that just hangs in memory, ready to do something .... WCF IS NOT ASP.NET!

The default setting when placed in IIS is as follows:

  • IIS /URL - WCF

  • , IIS ServiceHost - , ""

  • , URL-, , . ( ) ,

, , , :

  • ServiceHost, -,

  • "" .

+5

, . , . - , .

, WCF . -, . Application_Start Global.asax. ( ).

- , Application_BeginRequest Global.asax.

+2

, :

[ServiceContract]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class InstanceService
{
    private int _intValue;

    public InstanceService()
    {
        _intValue = 456;
    }

    [OperationContract]
    public int GetData()
    {
        return _intValue;
    }
}

GetData() 456.

0

, , . , WCF Windows ad hoc. , , . IIS-, , , .

wcf, IIS .

0

All Articles