Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 创建时加载到windows服务中的全局数据需要可由WCF dll访问_C#_Wcf_Windows Services - Fatal编程技术网

C# 创建时加载到windows服务中的全局数据需要可由WCF dll访问

C# 创建时加载到windows服务中的全局数据需要可由WCF dll访问,c#,wcf,windows-services,C#,Wcf,Windows Services,我有一个由windows服务包装的WCF dll(使用net.tcp绑定),我想在启动期间在服务中加载全局数据,该数据可以从dll中访问。这可能很简单,但我没有看到。有什么建议吗 namespace MyApp { [ServiceContract] public interface IMyApp { [OperationContract] bool Export(MyObj obj)

我有一个由windows服务包装的WCF dll(使用net.tcp绑定),我想在启动期间在服务中加载全局数据,该数据可以从dll中访问。这可能很简单,但我没有看到。有什么建议吗

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();

                }
            }

        }

    }

是否要从Windows服务的OnStart处理程序在WCF服务中设置全局变量?“服务”一词在这里是不明确的,因为它同时适用于WCF和Windows服务。对不起:-),我想在Windows service OnStart()方法中设置全局变量,而不是库类(WCF dll)。可能的答案/解释可能在这里。。。虽然和你的情况不完全一样。静态数据在WCFService中,而不是在外部@这个全局变量的性质是什么?一个可能的答案-您可以公开一个新的OperationContract来获取全局变量,并在OnStart()方法中调用它,对吗?谢谢您的建议。事实证明,在NetworkService帐户下运行服务会导致全局变量获取数据时出现问题。