Windows services 使用嵌入Windows服务的Quartz.Net

Windows services 使用嵌入Windows服务的Quartz.Net,windows-services,quartz.net,Windows Services,Quartz.net,我正在尝试使用Quartz.Net,以便在我开发的Windows服务中安排作业 我在Onstart方法中包含了以下代码,scheduler是一个类属性 专用只读IScheduler调度器 logger=LogManager.GetLogger(typeof(TelegestionService)) scheduler=new StdSchedulerFactory().GetScheduler() var作业=新作业详细信息(“作业1”、“组1”、类型(HelloJob)) var trigg

我正在尝试使用Quartz.Net,以便在我开发的Windows服务中安排作业

我在Onstart方法中包含了以下代码,scheduler是一个类属性
专用只读IScheduler调度器


logger=LogManager.GetLogger(typeof(TelegestionService))
scheduler=new StdSchedulerFactory().GetScheduler()
var作业=新作业详细信息(“作业1”、“组1”、类型(HelloJob))
var trigger=newsimpletrigger(“trigger1”,“group1”,运行时)
ScheduleJob(作业,触发器);

这对我来说很好。我得到了这份工作

现在,我正试图使调度器嵌入远程访问,基于Quartz源代码示例中的en Example12(控制台服务器/客户端工作正常)


var properties=new NameValueCollection()
属性[“quartz.scheduler.instanceName”]=“RemoteServer”
属性[“quartz.threadPool.type”]=“quartz.siml.SimpleThreadPool,quartz”
属性[“quartz.threadPool.threadCount”]=“5”
属性[“quartz.threadPool.threadPriority”]=“正常”
属性[“quartz.scheduler.exporter.type”]=“quartz.siml.RemotingSchedulerExporter,quartz”
属性[“quartz.scheduler.exporter.port”]=“555”
属性[“quartz.scheduler.exporter.bindName”]=“QuartzScheduler”
属性[“quartz.scheduler.exporter.channelType”]=“tcp”

scheduler=new StdSchedulerFactory(properties).GetScheduler()

服务正确启动,调度程序也正确启动,但我无法使用Console/Winform客户端远程调度作业(连接被拒绝)

我使用sysintransetcpview检查了服务器上的侦听端口,但找不到上面指定的555端口

我怀疑存在与.Net远程处理相关的问题,但无法找到解决方法。 有什么想法吗

提前感谢。

可以使用主机调度器,它将提供hostFactory,并通过HttpSelfHostServer使用该主机,http更好,因为您可以通过控制器调用作业。示例代码如下所示

希望这有帮助

using System;
using System.Configuration;
using System.Web.Http;
using System.Web.Http.SelfHost;
using Topshelf;
     class Program
    {
        static void Main(string[] args)
        {
            HostFactory.Run(hostConfigurator =>
            {
                if (!Uri.TryCreate("http://localhost:8080", UriKind.RelativeOrAbsolute, out var hostname))
                {
                    throw new ConfigurationErrorsException($"Could not uri");
                }

                var serviceName = "my service";

                var hostConfiguration = new HttpSelfHostConfiguration(hostname);
                hostConfiguration.Routes.MapHttpRoute("API", "{controller}/{action}/{id}", (object)new
                {
                    id = RouteParameter.Optional
                });

                var httpSelfHostServer = new HttpSelfHostServer(hostConfiguration);

                // Impl.Scheduler would be your implementation of scheduler
                hostConfigurator.Service<Impl.Scheduler>(s =>
                {
                    s.ConstructUsing(name => new Impl.Scheduler());
                    s.WhenStarted(tc =>
                    {
                        tc.Start();

                        httpSelfHostServer.OpenAsync().Wait();
                    });
                    s.WhenStopped(tc =>
                    {
                        tc.Stop();
                        //dispose scheduler implementation if using IOC container
                        httpSelfHostServer.CloseAsync().Wait();
                    });
                });
                hostConfigurator.RunAsLocalSystem();

                hostConfigurator.SetDescription(serviceName);
                hostConfigurator.SetDisplayName(serviceName);
                hostConfigurator.SetServiceName(serviceName);
            });
        }
    }
使用系统;
使用系统配置;
使用System.Web.Http;
使用System.Web.Http.SelfHost;
使用Topshelf;
班级计划
{
静态void Main(字符串[]参数)
{
运行(hostConfigurator=>
{
如果(!Uri.TryCreate(“http://localhost:8080“,UriKind.RelativeOrAbsolute,out var主机名))
{
抛出新的ConfigurationErrorsException($“无法uri”);
}
var serviceName=“我的服务”;
var hostConfiguration=新的HttpSelfHostConfiguration(主机名);
hostConfiguration.Routes.MapHttpRoute(“API”、“{controller}/{action}/{id}”,(对象)新建
{
id=路由参数。可选
});
var httpSelfHostServer=新的httpSelfHostServer(主机配置);
//Impl.Scheduler将是调度器的实现
hostConfigurator.Service(s=>
{
s、 ConstructUsing(name=>newimpl.Scheduler());
s、 开始时(tc=>
{
tc.Start();
httpSelfHostServer.OpenAsync().Wait();
});
s、 停止时(tc=>
{
tc.Stop();
//如果使用IOC容器,则处置计划程序实现
httpSelfHostServer.CloseAsync().Wait();
});
});
hostConfigurator.RunAsLocalSystem();
hostConfigurator.SetDescription(serviceName);
hostConfigurator.SetDisplayName(serviceName);
hostConfigurator.SetServiceName(serviceName);
});
}
}
可以使用主机调度器,该调度器将提供主机工厂,并通过HttpSelfHostServer使用该主机,http更好,因为您可以通过控制器调用作业。示例代码如下所示

希望这有帮助

using System;
using System.Configuration;
using System.Web.Http;
using System.Web.Http.SelfHost;
using Topshelf;
     class Program
    {
        static void Main(string[] args)
        {
            HostFactory.Run(hostConfigurator =>
            {
                if (!Uri.TryCreate("http://localhost:8080", UriKind.RelativeOrAbsolute, out var hostname))
                {
                    throw new ConfigurationErrorsException($"Could not uri");
                }

                var serviceName = "my service";

                var hostConfiguration = new HttpSelfHostConfiguration(hostname);
                hostConfiguration.Routes.MapHttpRoute("API", "{controller}/{action}/{id}", (object)new
                {
                    id = RouteParameter.Optional
                });

                var httpSelfHostServer = new HttpSelfHostServer(hostConfiguration);

                // Impl.Scheduler would be your implementation of scheduler
                hostConfigurator.Service<Impl.Scheduler>(s =>
                {
                    s.ConstructUsing(name => new Impl.Scheduler());
                    s.WhenStarted(tc =>
                    {
                        tc.Start();

                        httpSelfHostServer.OpenAsync().Wait();
                    });
                    s.WhenStopped(tc =>
                    {
                        tc.Stop();
                        //dispose scheduler implementation if using IOC container
                        httpSelfHostServer.CloseAsync().Wait();
                    });
                });
                hostConfigurator.RunAsLocalSystem();

                hostConfigurator.SetDescription(serviceName);
                hostConfigurator.SetDisplayName(serviceName);
                hostConfigurator.SetServiceName(serviceName);
            });
        }
    }
使用系统;
使用系统配置;
使用System.Web.Http;
使用System.Web.Http.SelfHost;
使用Topshelf;
班级计划
{
静态void Main(字符串[]参数)
{
运行(hostConfigurator=>
{
如果(!Uri.TryCreate(“http://localhost:8080“,UriKind.RelativeOrAbsolute,out var主机名))
{
抛出新的ConfigurationErrorsException($“无法uri”);
}
var serviceName=“我的服务”;
var hostConfiguration=新的HttpSelfHostConfiguration(主机名);
hostConfiguration.Routes.MapHttpRoute(“API”、“{controller}/{action}/{id}”,(对象)新建
{
id=路由参数。可选
});
var httpSelfHostServer=新的httpSelfHostServer(主机配置);
//Impl.Scheduler将是调度器的实现
hostConfigurator.Service(s=>
{
s、 ConstructUsing(name=>newimpl.Scheduler());
s、 开始时(tc=>
{
tc.Start();
httpSelfHostServer.OpenAsync().Wait();
});
s、 停止时(tc=>
{
tc.Stop();
//如果使用IOC容器,则处置计划程序实现
httpSelfHostServer.CloseAsync().Wait();
});
});
hostConfigurator.RunAsLocalSystem();
hostConfigurator.SetDescription(serviceName);
hostConfigurator.SetDisplayName(服务