Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.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服务在Windows 7上启动,但在Windows Server 2008 R2上启动失败_C#_Wcf_Debugging_Windows Services_Windows Server - Fatal编程技术网

C# Windows服务在Windows 7上启动,但在Windows Server 2008 R2上启动失败

C# Windows服务在Windows 7上启动,但在Windows Server 2008 R2上启动失败,c#,wcf,debugging,windows-services,windows-server,C#,Wcf,Debugging,Windows Services,Windows Server,我创建了一个通过托管windows服务部署的wcf服务。onstart()的作用是为wcf服务创建并打开一个tcp主机 在Windows7中一切正常,但当我尝试在WindowsServer2008R2中安装该服务时,该服务会启动,然后停止,并出现错误,有时服务会在无事可做时停止。它在网络服务帐户下运行 我在windows日志中找不到任何有用的东西 我尝试过安装dubug build和call debugger.launch(),但它不起作用。我无法使用remode debug,因为进程的打开时间

我创建了一个通过托管windows服务部署的wcf服务。onstart()的作用是为wcf服务创建并打开一个tcp主机

在Windows7中一切正常,但当我尝试在WindowsServer2008R2中安装该服务时,该服务会启动,然后停止,并出现错误,有时服务会在无事可做时停止。它在网络服务帐户下运行

我在windows日志中找不到任何有用的东西

我尝试过安装dubug build和call debugger.launch(),但它不起作用。我无法使用remode debug,因为进程的打开时间不够长,我无法连接到它。 我真的不知道该怎么办。这是我的密码:

    protected override void OnStart(string[] args)
    {
        System.Diagnostics.Debugger.Launch();

        try
        {

            //if (!System.Diagnostics.EventLog.SourceExists("i2s CU Service (eng)"))
            //{
            //    System.Diagnostics.EventLog.CreateEventSource("i2s CU Service", "Application");
            //}
            System.Diagnostics.EventLog.CreateEventSource("i2s CU Service", "Application");
        }
        catch (Exception)
        {
            //throw;
        }
        eventLog1.Source = "i2s CU Service";
        eventLog1.Log = "Application";

        if (serviceHost != null)
        {
            serviceHost.Close();
        }

        System.Configuration.AppSettingsReader reader = new System.Configuration.AppSettingsReader();
        Uri tcpUri = null;
        try
        {
            tcpUri = new Uri((string)reader.GetValue("Uri", typeof(string))); //net.tcp://localhost:8008/i2sServer

            serviceHost = new ServiceHost(typeof(ConcurrentUsers), tcpUri);

            // Create a binding that uses TCP and set the security mode to none.
            NetTcpBinding b = new NetTcpBinding();
            b.Security.Mode = SecurityMode.None;

            // Add an endpoint to the service.
            serviceHost.AddServiceEndpoint(typeof(IConcurrentUsers), b, "");

            // Open the ServiceHostBase to create listeners and start 
            // listening for messages.
            serviceHost.Open();
        }
        catch (Exception ex)
        {
            eventLog1.WriteEntry(ex.Message, EventLogEntryType.Error);
        }


        if (serviceHost.State == CommunicationState.Opened)
        {
            eventLog1.WriteEntry("Service started.", EventLogEntryType.Information);
        }
    }

    protected override void OnStop()
    {
        if (serviceHost != null)
        {
            serviceHost.Close();
            serviceHost = null;
        }
        eventLog1.WriteEntry("Service stopped.", EventLogEntryType.Information);
    }
这段代码在Windows7中运行得非常好,但我无法让它在Win2008R2服务器上运行


提前感谢

将您的应用程序重构为一个控制台应用程序,然后在所需的环境中运行它,以便能够轻松地对其进行调试


我确信,一旦您在分配给windows服务的同一用户帐户下运行控制台副本,问题就会暴露出来

如果您不处理第一个异常,问题可能就发生在那里。我已经尝试删除了整个错误日志,但在windows 7中,这似乎不是问题,并且之前声明的调试器没有启动!所以你不认为服务有问题,而认为内容有问题。好的,我会这么做的。确实,问题不在于平台,而在于不允许网络服务帐户访问服务器计算机上的windows日志。因此,将服务作为控制台应用程序使用确实很有帮助。谢谢我的荣幸,阿瑞斯。很高兴听到一切进展顺利。