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

Moh*_*ani 50 c# web-applications ravendb asp.net-mvc-4 asp.net-web-api

我在我的应用程序中使用了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();
Run Code Online (Sandbox Code Playgroud)

Web.config在服务层中实现这些设置:

<connectionStrings>
    <add name="RavenDB" connectionString="DataDir=~\App_Data\RavenDatabase" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)

有没有我错过的设置?

我需要将任何设置应用于将Raven Studio指向另一个端口吗?

Mat*_*int 11

我能够重现您描述的体验的唯一方法是故意创建端口冲突.默认情况下,RavenDB的Web服务器托管在端口8080上,所以如果你没有更改raven的端口,那么你必须在端口8080上托管你的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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

protected void Application_Start()
{
    // with your other startup registrations
    RavenConfig.Register();
}

protected void Application_End()
{
    // for a clean shutdown
    RavenConfig.Cleanup();
}
Run Code Online (Sandbox Code Playgroud)