南希听两个不同的地址

时间:2017-11-04 16:46:15

标签: c# nancy

我想用两种API编写程序。一个API应该监听IP地址(例如192.168.1.20)。此API必须具有2种方法。其他API应该监听localhost并有一个方法。我试着用南希。我读了这个主题Nancy - two modules listening on different ports,但我有一些错误。你可以帮我编译吗?

Error   CS1061  'Bootstrapper' does not contain a definition for 'GetModuleKeyGenerator' and no extension method 'GetModuleKeyGenerator' accepting a first argument of type 'Bootstrapper' could be found (are you missing a using directive or an assembly reference?) 

此错误出现在此类的返回行

 public class Bootstrapper : DefaultNancyBootstrapper
{
    /// <summary>
    /// Register only NancyModules found in this assembly
    /// </summary>
    protected override IEnumerable<ModuleRegistration> Modules
    {
        get
        {
            return GetType().Assembly.GetTypes().Where(type => type.BaseType == typeof(NancyModule)).Select(type => new ModuleRegistration(type, this.GetModuleKeyGenerator().GetKeyForModuleType(type)));
        }
    }
}

所有文件的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using Nancy;
using Nancy.Bootstrapper;
using Nancy.Hosting.Self;

namespace Server1
{
    public class Server : NancyModule
    {
        private static NancyHost _server;

        public static void Start()
        {
            _server = new NancyHost(new Bootstrapper(), new Uri("http://localhost:8686"));
            _server.Start();
        }

        public Server()
        {
            Get["/"] = _ => "this is server 1";
        }
    }

    public class Bootstrapper : DefaultNancyBootstrapper
    {
        /// <summary>
        /// Register only NancyModules found in this assembly
        /// </summary>
        protected override IEnumerable<ModuleRegistration> Modules
        {
            get
            {
                return GetType().Assembly.GetTypes().Where(type => type.BaseType == typeof(NancyModule)).Select(type => new ModuleRegistration(type, this.GetModuleKeyGenerator().GetKeyForModuleType(type)));
            }
        }
    }
}

感谢你的时间!

0 个答案:

没有答案