如何使用双层架构将UseEmbeddedHttpServer设置为true时,使我的RavenDB应用程序正确执行?

我在我的应用程序中使用RavenDB-Embedded 2.0.2230与不同程序集中的ASP .Net Web API交互。

当我在文档存储上设置UseEmbeddedHttpServer = true时,第一次向RavenDB发送请求时,它正确执行,但是当我第二次尝试时,我的应用程序显示Raven Studio。

当我删除UseEmbeddedServer设置时,我的应用程序运行没有任何问题。

我的RavenDB在数据层中configuration了以下代码:

 this.documentStore = new EmbeddableDocumentStore { ConnectionStringName = "RavenDB", UseEmbeddedHttpServer = true }.Initialize(); 

并且Web.config实现在服务层中具有这些设置:

 <connectionStrings> <add name="RavenDB" connectionString="DataDir=~\App_Data\RavenDatabase" /> </connectionStrings> 

有没有我错过的设置?

有什么设置,我需要申请点Raven Studio到不同的端口?

我能够重现你所描述的经验的唯一方法就是有意造成港口冲突。 默认情况下,RavenDB的Web服务器托pipe在端口8080,所以如果你不改变乌鸦的端口,那么你必须在8080端口上托pipe你的WebApi应用程序。如果不是这样,请让我知道在评论中,但我会承担它是如此。

所有你需要做的改变端口Raven使用的是在调用Initialize方法之前修改端口值。

将这个RavenConfig.cs文件添加到您的App_Startup文件夹中:

 using Raven.Client; using Raven.Client.Embedded; namespace <YourNamespace> { public static class RavenConfig { public static IDocumentStore DocumentStore { get; private set; } public static void Register() { var store = new EmbeddableDocumentStore { UseEmbeddedHttpServer = true, DataDirectory = @"~\App_Data\RavenDatabase", // or from connection string if you wish }; // set whatever port you want raven to use store.Configuration.Port = 8079; store.Initialize(); this.DocumentStore = store; } public static void Cleanup() { if (DocumentStore == null) return; DocumentStore.Dispose(); DocumentStore = null; } } } 

然后在你的Global.asax.cs文件中,执行以下操作:

 protected void Application_Start() { // with your other startup registrations RavenConfig.Register(); } protected void Application_End() { // for a clean shutdown RavenConfig.Cleanup(); } 

当您在EmbeddableDocumentStore中启用HttpServer时,ravenDB会“劫持”web应用程序,并开始在应用程序运行的相同端口上进行侦听。

Oren Eini:从IIS内部使用UseEmbeddedHttpServer时,会从IIS获取端口。 您需要再次设置值

https://groups.google.com/forum/?fromgroups=#!topic/ravendb/kYVglEoMncw

防止它的唯一方法是转向乌鸦http服务器或将其分配给不同的端口

 int ravenPort = 8181; NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenPort); var ds = new EmbeddableDocumentStore { DataDirectory = [DataFolder], UseEmbeddedHttpServer = true, Configuration = {Port = ravenPort} };