问题:

当我尝试启动在C#中创建的Windows服务时出现此错误:

替代文字

到目前为止,我的代码:

private ServiceHost host = null;

public RightAccessHost()
{
    InitializeComponent();
}

protected override void OnStart(string[] args)
{
    host = new ServiceHost(typeof(RightAccessWcf));
    host.Open();
}

protected override void OnStop()
{
    if (host != null)
        host.Close();
    host = null;
}

更新#1

我通过向帐户NETWORK SERVICE授予权限解决了上述问题,但现在又遇到了另一个问题:

替代文字

更新#2

服务无法启动。 System.InvalidOperationException:服务’RightAccessManagementWcf.RightAccessWcf’具有零个应用程序端点(非基础结构)。 这可能是因为没有为您的应用程序找到配置文件,或者是因为在配置文件中找不到与服务名称匹配的服务元素,或者因为在服务元素中未定义端点。 在System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreNonMexEndpoints(ServiceDescription描述)在System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription描述,ServiceHostBase serviceHost)在System.ServiceModel.ServiceHostBase.InitializeRuntime()在System.ServiceModel.ServiceHostBase.OnOpen()在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)在C:\\ Users中的RightAccessHosting.RightAccessHost.OnStart(String [] args)处。

I’m getting this error when I try to start a windows service I’ve created in C#:My Code so far:Update #1I solved the issue above by granting permissions to the account NETWORK SERVICE but now I have an another problem:Update #2Service cannot be started.System.InvalidOperationException: Service ‘RightAccessManagementWcf.RightAccessWcf’ has zero application (non-infrastructure) endpoints.This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.at System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreNonMexEndpoints(ServiceDescription description) at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) at System.ServiceModel.ServiceHostBase.InitializeRuntime() at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at RightAccessHosting.RightAccessHost.OnStart(String[] args) in C:\\Users….

问题:

通常,我收到此错误:(本地计算机上的“服务名称”服务启动然后停止。如果我的代码出现问题,如某些服务未被其他服务或程序使用,则会自动停止驱动路径等.Windows服务无法启动。

如果达到大小限制,我有一个备份文件夹/文件的Windows服务到一个位置。 详细信息都是由Windows服务在启动时读取的XML配置提供的。 我有一个单独的窗体,有一个按钮,完全符合我的Windows服务的启动。 在将其放入Windows服务之前,我使用我的Windows窗体来调试代码。

当我启动我的Windows窗体。 它做了它想做的事情。 当我把我的代码放在Windows服务OnStart()方法时出现错误。

这是我的代码:

protected override void OnStart(string[] args)
{

    private static string backupConfig = @"D:\LogBackupConfig\backupconfig.xml";
    private static string serviceStat = @"D:\LogBackupConfig\Status.txt";
    private static string fileFolderStat = @"D:\LogBackupConfig\FileFolderStat.txt";

    protected override void OnStart(string[] args)
    {
        if (File.Exists(backupConfig))
        {
            FileSystemWatcher watcher = new FileSystemWatcher();
            XmlTextReader reader = new XmlTextReader(backupConfig);

            XmlNodeType type;
            List<string> listFile = new List<string>();
            string fileWatch = "";

            //this loop is for reading XML elements and assigning to variables
            while (reader.Read())
            {
                type = reader.NodeType;
                if (type == XmlNodeType.Element)
                {
                    if (reader.Name == "File")
                    {
                        reader.Read();
                        fileWatch = reader.Value;
                    }
                    else if (reader.Name == "Folder")
                    {
                        reader.Read();
                        fileWatch = reader.Value;
                    }
                }
            }
            reader.Close();

            watcher.Path = fileWatch;
            watcher.Filter = "*.*";

            //this loop reads whether the service will watch a file/folder
            XmlTextReader reader1 = new XmlTextReader(backupConfig);
            while (reader1.Read())
            {
                type = reader1.NodeType;
                if (type == XmlNodeType.Element)
                {
                    if (reader1.Name == "File")
                    {
                        watcher.IncludeSubdirectories = false;
                        watcher.Changed += new FileSystemEventHandler(OnChangedFile);
                    }
                    else if (reader1.Name == "Folder")
                    {
                        watcher.IncludeSubdirectories = true;
                        watcher.Changed += new FileSystemEventHandler(OnChangedFolder);
                    }
                }
            }
            reader1.Close();

            watcher.EnableRaisingEvents = true;

        }
        else
        {
            StreamWriter sw = new StreamWriter(serviceStat, true);
            sw.WriteLine("File not found. Please start the Log Backup UI first.");
            sw.Close();
        }
    }

我不知道是什么让Windows服务无法启动,Windows窗体模拟器工作正常。 什么似乎是问题?

更新:经过多次试验,我注意到只使用文件夹目录(w / out文件),Windows服务不起作用。 当我用特定文件(包括其目录)替换fileWatch变量时,Windows服务启动了。 当我将其更改回文件夹位置时,它无法正常工作。 我认为文件夹位置在filewatcher中不起作用。

当我尝试创建一个监视文件夹位置的新Windows服务时,它工作..但是,当我在原始的Windows服务中尝试相同的位置时,它不起作用! 我很精神!#ed ed! 似乎每次我放置一个新的代码/函数时我都必须创建一个新的Windows服务并构建安装程序。这样我就可以跟踪我收到错误的位置。

Usually, I get this error: (The “service name” service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other service or programs) when there’s something wrong with my code, like non-existing drive paths, etc. The windows service will not start.I have a windows service that backs up folder/files, to a location if it reached the size limit.Details are all provide by an XML Configuration that the windows service reads on start.I have a separate windows forms that has a button that does exactly what my windows service’s onstart is doing.I use my windows forms for debugging the code before I put it in my windows service.When I start my windows forms.It does what it suppose to do.When I put my code in the windows service OnStart() method the error showed up.Here’s my code:I don’t know what keeps the windows service not starting, the windows form simulator worked fine.What seems to be the problem?UPDATE: After many trials I’ve noticed that using only a folder directory (w/out file), the windows service doesn’t work.When I replaced the fileWatch variable with a specific file (including its directory), the windows service started.When I changed it back to a folder location, it didn’t work.What I think is that folder locations doesn’t work in a filewatcher.When I tried creating a new windows service that watches a folder location, it worked.. However, when I tried the same location in my original windows service, it didn’t work!I was mindf$#*ed!It seems that I have to create a new windows service and build the installer everytime I place a new code/function.. This way I can keep track where I get an error.

问题:

我使用C#.NET开发了Windows服务以生成PDF报告。 要生成PDF文件,我正在使用第三方dll。 该应用程序正在我的Windows XP平台上运行。 Windows Server 2008 64位版本中部署服务时,出现此错误:

由于以下错误,无法检索具有CLSID {46521B1F-0A5B-4871-A4C2-FD5C9276F4C6}的组件的COM类工厂。

我使用regsvr32命令注册了DLL。 我可以在注册表中看到此CLSID。 但是问题仍然存在。

可能是什么问题呢?

I developed a Windows service using C#.NET to generate PDF report.To generate PDF file I am using a third party dll.The application is running in my Windows XP platform.When I deployed the service in Windows Server 2008 64 bit version, I got this error:Retrieving the COM class factory for component with CLSID {46521B1F-0A5B-4871-A4C2-FD5C9276F4C6} failed due to the following error: 80040154.I registered the DLL using the regsvr32 command.I able to see this CLSID in the registry.But the problem persists.What could be the problem?

问题:

我尝试使用sc delete <service name> Windows服务,并遇到以下错误:

[SC] DeleteService失败1072:

指定的服务已标记为删除。

我已经完成的工作:

问题仍然存在。

你下一步怎么做?

I try to remove a Windows Service with sc delete <service name> , and encounter the following error:[SC] DeleteService FAILED 1072:The specified service has been marked for deletion.What I’ve already done:Stopped the service, obviously.The sc queryex "<service name>" gives the following result:Ensured that Microsoft Management Console is closed ( taskkill /F /IM mmc.exe ),Ensured that Event Viewer is closed ,Removed the key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\<service name> from the registry .Due to this removal, services.msc still shows the service (with a name, but no status or startup type), but the description is “<Failed to Read Description.Error Code: 2 >”.When attempting to view the properties, “The system cannot find the file specified.” is shown five times.The problem persists.What is the next step?