How can i initialise a server on startup?

前端 未结 2 930
迷失自我
迷失自我 2021-01-24 02:06

I need to make some connections on startup of a server. I\'m using the wcf technology for this client-server application. The problem is that the constructor of the server isn\'

相关标签:
2条回答
  • 2021-01-24 02:25

    There are two ways I can immediately think of.

    One - you can implement your solution as windows service

    and Second - let a dummy client program call your server at start-up.

    0 讨论(0)
  • 2021-01-24 02:30

    WCF will instantiate your MonitoringSystemService class as needed. It won't instantiate it until the first client makes a connection, and if you get a lot of client connections all at once, it will instantiate a few MonitoringSystemServices to deal with the load.

    You can disable this behaviour, and instead just use one instance of MonitoringSystemService that gets created when your program starts. Instead of telling WCF which type it should be automatically instantiating, you just instantiate it yourself and pass it in:

    _svc = new ServiceHost(new MonitoringSystemService()), address);
    

    You gain control of when the MonitoringSystemService contructor runs, at the expense of scalability.

    Alternatively (if you need the scalability), you could "initialize the connections" in your Main method, but be aware that WCF could instantiate multiple MonitoringSystemServices that would need to share those connections.

    0 讨论(0)
提交回复
热议问题