0

I have a WCF dll that is wrapped by a windows service (using net.tcp binding) and I want to load in global data in the service during OnStart that is accessible from within the dll. This is probably pretty simple, but I am not seeing it. Any suggestions?

namespace MyApp
    {
        [ServiceContract]
        public interface IMyApp
        {   
            [OperationContract]
             bool Export(MyObj obj);  // omitted definition of myObj for brevity
        }

        [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
        class MyWCF : IMyApp
        {
            public bool Export(MyObj obj) 
            { 
            bool bResult;
                string sExportPath = GlobalObject.GetEnvironmentPath(obj.Env); //GlobalObject class is defined within this namespace

            bResult = RetrieveDocument(obj.ID, sExportPath);    
                return bResult;
            }
        }
    }

    ------------------------- windows service  ------------------------------
    using MyApp;

    namespace MyService
    {
        public partial class MyService: ServiceBase
        {
            internal static ServiceHost objServiceHost = null;


            public MyService()
            {
                InitializeComponent();
            }

            protected override void OnStart(string[] args)
            {
                if (objServiceHost != null)
                    objServiceHost.Close();

                bServiceStopped = false;
                objServiceHost = new ServiceHost(typeof(MyWCF));
                objServiceHost.Open();


                Trace.TraceInformation("Load globaldata");
                if (!GlobalObject.LoadGlobalData()))
                {
                    Log("Failure attempting to Load Global Data...");

                    var controller = new System.ServiceProcess.ServiceController("MyService");
                    controller.Stop();

                }
            }

        }

    }
ERukes
  • 51
  • 6
  • Do you want to set a global variable in your WCF service from your Windows service's OnStart handler? The word 'service' is ambiguous here, since it applies to both WCF and Windows service. – Channs Jul 30 '12 at 19:12
  • Sorry :-), I want to set the global variable within the Windows Service OnStart() method as opposed to the library class (WCF dll). – ERukes Jul 30 '12 at 20:18
  • Possible answer/explanation might be here ... though not exactly same situation as you ...i.e. the static data is in the WCFService rather than outside... http://stackoverflow.com/questions/1826324/how-to-write-a-wcf-service-with-in-memory-persistent-storage – Colin Smith Jul 30 '12 at 21:59
  • @ERukes - What is the nature of this global variable? One possible answer - you could expose a new OperationContract to fetch the global variable and call that in the OnStart() method, right? – Channs Jul 31 '12 at 12:43
  • Thanks for the suggestions. It turned out that it was an issue with running the service under the NetworkService account was causing problems with my global variables getting data. – ERukes Aug 02 '12 at 21:18

0 Answers0