【发布时间】: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