1

我开始学习 RavenDB。我在服务器机器上安装了服务器版本,并将客户端 dll 添加到一个简单的控制台应用程序中。当我尝试运行应用程序时,它给了我一个 WebException:“请求被中止:请求被取消。”

这是代码:

public class Article : AbstractIndexCreationTask<Article>  
  {
    public string Id { get; set; }
    public string Text { get; set; }
    public string Title { get; set; }

    public Article()
    {
        Map = articles => from article in articles select new { article.Text };  
    }
} 

       static void Main(string[] args)
    {
        var ravenIntroArticle = new Article()
        {
            Text = "RavenDB fits into a movement that is called ...",
            Title = "RavenDB Introduction",
        };

        var csharpUsingArticle = new Article()
        {
            Text = "The full value of the C# using statement ...",
            Title = "Your Friend the C# Using Statement",
        };

        var nutsAndProteinArticle = new Article()
        {
            Text = "Nuts are a great source of protein ...",
            Title = "Nuts and Protein",
        };

        using (IDocumentStore documentStore = new DocumentStore() { Url = "http://rtest01:8081" })
        {
            documentStore.Initialize();
            using (IDocumentSession session = documentStore.OpenSession())
            {
                session.Store(ravenIntroArticle); // the exception happens here
                session.Store(csharpUsingArticle);
                session.Store(nutsAndProteinArticle);
                session.SaveChanges();
            }
        }

在此处输入图像描述

这是我尝试在本地服务器“ http://localhost:8080 ”上运行它时发生的情况

在此处输入图像描述

你能告诉我我错过了什么吗?

谢谢。

4

2 回答 2

1

Code Url 中的端口 8080 与运行 RavenDb Server 的控制台中显示"http://rtest01:8080"的端口不匹配。8081

于 2012-07-20T19:49:37.460 回答
0

好吧,我花了一点时间才意识到该代码出了什么问题,但现在我看到它真的很清楚,您正在尝试存储一个AbstractIndexCreationTask<Article>而不是 POCO 类,让我们用一个示例来展示它:

//This is the POCO entity that we will be storing into Raven
public class Article
{
    public string Id { get; set; }
    public string Text { get; set; }
    public string Title { get; set; }
}

//This is the IndexCreationTask that builds the index
public class Article_Text : AbstractIndexCreationTask<Article>
{
    public Article_Text()
    {
        Map = articles => from article in articles select new { article.Text };
    }
}

static class Program
{
    static void Main()
    {
        var ravenIntroArticle = new Article()
        {
            Text = "RavenDB fits into a movement that is called ...",
            Title = "RavenDB Introduction",
        };

        var csharpUsingArticle = new Article()
        {
            Text = "The full value of the C# using statement ...",
            Title = "Your Friend the C# Using Statement",
        };

        var nutsAndProteinArticle = new Article()
        {
            Text = "Nuts are a great source of protein ...",
            Title = "Nuts and Protein",
        };

        using ( IDocumentStore documentStore = new DocumentStore { Url = "http://rtest01:8081" }.Initialize() )
        {
            // This is the static call to create the index
            IndexCreation.CreateIndexes( typeof( Article_Text ).Assembly, documentStore );
            using ( IDocumentSession session = documentStore.OpenSession() )
            {
                session.Store( ravenIntroArticle ); // no more exceptions here!
                session.Store( csharpUsingArticle );
                session.Store( nutsAndProteinArticle );
                session.SaveChanges();
            }
        }

    }
}

于 2012-08-10T17:10:23.503 回答