【问题标题】:ServiceStack Service startup errorServiceStack 服务启动错误
【发布时间】:2016-06-23 16:45:56
【问题描述】:

我正在使用下面的代码,但在 appHost.Start(listeningOn) 这一行出现错误。

我删除了 bin 和 obj 文件夹,甚至重新启动了 Visual Studio,但错误仍然存​​在:

代码如下:

var listeningOn = $"http://*:{Globals.RestServicePort}/";
var appHost = new AppHost();
appHost.Init();
appHost.Start(listeningOn);

这是错误:

该进程无法访问该文件,因为它正被另一个进程使用

堆栈跟踪:

at ServiceStack.WebHost.Endpoints.Support.HttpListenerBase.Start(String urlBase, WaitCallback listenCallback) at ServiceStack.WebHost.Endpoints.Support.HttpListenerBase.Start(String urlBase) at NotifierServer.WindowsService.NotificationService.Start() in E:\dev\projectname\WindowsService\mService.cs:line 23

AppHost 类:

public class AppHost : AppHostHttpListenerBase
{
    public AppHost()
        : base("HttpListener Self-Host", typeof(NotifierRestService).Assembly)
    {
        ////disable metadata
        //SetConfig(new EndpointHostConfig
        //{
        //    EnableFeatures = Feature.All.Remove(Feature.Metadata)
        //});
    }

    public override void Configure(Funq.Container container)
    {
        container.Register<IResourceManager>(new ConfigurationResourceManager());

        Plugins.Add(new AuthFeature(() => new AuthUserSession(),
            new IAuthProvider[]
            {
                new BasicAuthProvider(), //Sign-in with HTTP Basic Auth
                new CredentialsAuthProvider(), //HTML Form post of UserName/Password credentials
            }));

        Plugins.Add(new RegistrationFeature());

        // use redis cache server
        container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("localhost:6379"));
        container.Register(c => c.Resolve<IRedisClientsManager>().GetCacheClient());

        // for authentication
        var dbFactory = new OrmLiteConnectionFactory(Globals.ConnectionStringNotifier,
            ServiceStack.OrmLite.PostgreSqlDialect.Provider);

        var userRep = new OrmLiteAuthRepository(dbFactory);
        container.Register<IUserAuthRepository>(userRep);

        // create necessary auth tables
        userRep.CreateMissingTables();
    }

【问题讨论】:

  • 听起来你有一个挂起的进程并没有消失。尝试在任务管理器中找到它和/或重新启动系统。
  • 我已经删除了与 Visual Studio 以及我的服务相关的所有进程,但错误仍然存​​在,现在无法重新启动机器,因为这是服务器机器。
  • 那么肯定是与VS无关的进程。 :)

标签: c# servicestack


【解决方案1】:

您需要在异常中包含完整的 StackTrace,提供的通用 ServiceStack 启动代码与您收到的错误无关。

异常表明您正在尝试访问由另一个进程使用的文件。您首先需要确定哪个文件有问题,然后您可以使用Process Explorer to find out which process is locking it

同样在低端口号上运行需要管理员权限,您可以通过选择端口号 >2000 来避免。

【讨论】:

  • StackTrace added 我还添加了 AppHost 类实现。
  • @Ali 您是否尝试过访问该 url 以查看是否已经在运行?更改端口是否有效?
  • 是的,目前我正在进程资源管理器中检查进程并更改端口,即 1338 仍然抛出相同的错误。
  • @Ali 我的意思是在浏览器中转到http://localhost:1338 以查看是否已经在运行,否则尝试将端口号更改为 > 2000 的数字。
  • @Ali ok 不确定错误消息,但在低端口上运行需要管理员权限,这可能与您的问题有关。
猜你喜欢
  • 1970-01-01
  • 2011-07-25
  • 2012-12-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-01
  • 2019-02-26
  • 2017-06-14
  • 2012-03-05
相关资源
最近更新 更多