我使用的是以下代码,但我在此行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();
}
答案 0 :(得分:1)
您需要将完整的StackTrace包含在Exception中,所提供的通用ServiceStack启动代码对您接收的错误无关紧要。
异常表示您正在尝试访问其他进程使用的文件。您首先需要确定哪个文件存在问题,然后您可以使用Process Explorer to find out which process is locking it。
同样在低端口号上运行需要管理员权限,您可以通过选择端口号&gt; 2000来避免管理员权限。