简体   繁体   中英

Sharing Console Application object to Self-Host WCF Service

I need to share my application statistics via a wcf service. I'm able to self-host my wcf service but ServiceHost object constructor is default leaving me to unable to initialize other member variables of my service.

Sample:

public interface IService
{
   //some operations here 
}

public class Service : IService
{
  object myObject;
  //implementation of IService
}

myObject is my console application object ( List ) and I wanted to make my service to be able to look into it. Is there any way I can reference it on my WCF Service?

您可以通过创建自定义IInstanceProvider自己提供服务的实例。

You could use this approach to the get handle on your ServiceHost instance in your service implementation code:

ServiceHostBase base = OperationContext.Current.Host;

Now you have a link to to your service host - anything publicly available and accessible can be read (preferably not set, since there might be many service class instances running).

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