简体   繁体   中英

Call a WCF Operation from Windows Service WCF Host

I am new to WCF programming. Here's what I need:

  1. A Windows service that hosts a WCF Service. (Done)
  2. A client application that can call WCF Service operations such as GetValue() from the running Windows service (Done)
  3. The Windows service needs to call the operation Start() from the WCF service when the Windows service starts. The application in (2) could not retrieve data without the Windows service calling Start() operation first. (Not done)

The Windows service needs to start once the PC starts. Then it should begin logging some data. The user can run the client application anytime to retrieve logged data.

However, I could not do the automated logging part because the client is the one who invokes the constructor of the WCF Service. This cannot be done inside the windows service's OnStart() method.

Is there a way to invoke a WCF operation from the Onstart() method of Windows service?

As - if you didn't configure it otherwise - a new instance of the WCF service class is created upon every call from the client, you could yourself also create a new instance of the class and just call your method. From your service's point of view, it is just a normal class.

It would help greatly if you could elaborate on what's done in Start .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM