当使用2层架构并将UseEmbeddedHttpServer设置为true时,我该如何使我的RavenDB应用程序正常执行?

51

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

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

当我移除UseEmbeddedServer的设置后,我的应用程序可以正常运行。

我的RavenDB配置如下(在数据层):

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

在服务层中,Web.config 的实现具有以下设置:

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

我有没有漏掉任何设置?

我需要应用哪些设置来将Raven Studio指向不同的端口?


1
在实例化“DocumentStore”之后,但在调用其上的“Initialize()”之前,您可以执行“documentStore.Configuration.Port = <port value>”。 - Cristian Lupascu
RavenDB-Embedded不稳定版本的Raven.Client.IDocumentStore中未知Configuration属性。 - Mohsen Alikhani
2
没错,它不在IDocumentStore接口上,因为那也用于非嵌入式。它在EmbedddableDocumentStore实现上。如果你正在传递一个IDocumentStore,只需将其强制转换回来。((EmbeddableDocumentStore)mystore).Configuration.Port = 8080 - Matt Johnson-Pint
我认为你可以通过更改服务器的配置选项使其在另一个主机:端口组合上工作,查看这里,并查找Http设置。 - VoidMain
请在RavenDB谷歌群组列表上提问:https://groups.google.com/forum/?fromgroups#!forum/ravendb - wal
你能否停止频繁地进行这些微小的编辑以提高你的问题的曝光率?如果你需要答案,可以考虑发起一个悬赏。 - BoltClock
2个回答

12

我能够重现你所描述的经历的唯一方法是有意地创建一个端口冲突。默认情况下,RavenDB的Web服务器托管在8080端口上,因此如果您没有更改Raven的端口,则必须将WebApi应用程序托管在8080端口上。如果不是这种情况,请在评论中让我知道,但我会假设是这样。

要更改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();
}

2
当您在嵌入式文档存储中启用HttpServer,RavenDB会“劫持”Web应用程序并开始侦听运行应用程序的相同端口。
引用: Oren Eini: 当您从IIS内部使用UseEmbeddedHttpServer时,它会从IIS获取端口。 您需要再次设置该值。
在https://groups.google.com/forum/?fromgroups=#!topic/ravendb/kYVglEoMncw上
防止这种情况的唯一方法是关闭Raven HTTP服务器或将其分配给另一个端口。
int ravenPort = 8181;
NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenPort);
var ds = new EmbeddableDocumentStore {
   DataDirectory = [DataFolder],    
   UseEmbeddedHttpServer = true,    
   Configuration = {Port = ravenPort}
};

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接