2010-09-28 44 views
2

我正在構建一個簡單的ASP.NET MVC 2.0 Web應用程序。我想提供一個AtomPub端點,以便我可以從Windows Live Writer發佈/更新內容。我原本以一組自定義的ActionResults作爲Controller實現AtomPub協議。這工作,直到我試圖獲得身份驗證工作,當我意識到獲得基本或摘要身份驗證(WLW所必需的)在我的基於Forms-Auth的MVC應用程序中工作將會有問題。在ASP.NET MVC 2.0中配置簡單的WCF服務端點

所以,現在我決定將AtomPub邏輯移動到MVC應用程序內的WCF服務。我創建了一個名爲AtomPub.svc的新WCF服務。添加以下到我的web.config文件:

<system.serviceModel> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior name=""> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
</system.serviceModel> 

而且,我的AtomPub.svc.cs後面的代碼看起來是這樣的:

namespace Web 
{ 
    using System.ServiceModel; 
    using System.ServiceModel.Web; 

    [ServiceContract] 
    public partial class AtomPub 
    { 
     [WebGet(UriTemplate = "?test={test}")] 
     [OperationContract] 
     public string DoWork(string test) 
     { 
      return test; 
     } 
    } 
} 

我還添加了路由排除排除從這個端點MVC的路由處理。

現在,我是WCF的總Noob,所以我確信我在做一些錯誤的事情。正如我正在寫這篇文章,端點的根似乎正在工作,因爲我得到一個AtomPub服務頁面。但是,URL模板無法正常工作,我不知道如何才能使其工作。我很樂意聽取您的建議。

順便說一句,我試圖儘可能簡化這個總體實現。所以,我不打算引入對實體框架的依賴,所以我可以使用WCF數據服務。我也不想將WCF端點移動到一個單獨的項目中,儘管我可以很容易地將它部署到W2k3/IIS6環境。

回答