2012-07-20 33 views
1

我開始學習RavenDB。我在服務器機器上安裝了Server版本,並將Client dll添加到簡單的控制檯應用程序中。當我試圖運行應用程序時,它給了我一個WebException:「請求被中止:請求被取消。」RavenDB session.Store例外

下面是代碼:

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

enter image description here

這是當我嘗試在本地服務器上運行 「http://localhost:8080

enter image description here

你能告訴發生了什麼我錯過了什麼?

謝謝。

+0

我們需要一些更多的信息,如:服務器是否在IIS中運行?如果情況如此,那麼您可能需要調整保留,並將其從「獲取」變爲raven.server.config中的「全部」。 – VoidMain 2012-07-20 18:57:32

+0

請在我編輯的帖子中看到圖片。 – 2012-07-20 19:47:29

+0

機器之間是否有防火牆?什麼是安全設置?當你在一臺機器上運行它時會發生什麼? – 2012-07-21 09:10:17

回答

1

代碼網址"http://rtest01:8080"中的端口8080與運行RavenDb服務器的控制檯中顯示的端口8081不匹配。

+0

對,我修正了它,但結果是一樣的:(我再次編輯我的帖子,也許它會擺脫更多的光線 – 2012-07-20 20:01:07

+0

你的文章類有一個Id屬性? – 2012-07-20 21:23:15

+0

是的,它有Id。 – 2012-07-23 11:40:05

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

    } 
}