在ASP中配置一个简单的WCF服务端点。NET MVC 2.0

时间:2021-07-24 16:51:03

I'm building a simple ASP.NET MVC 2.0 web application. I'd like to serve up a AtomPub endpoint so that I can publish/update content from Windows Live Writer. I originally went down the path of implementing the AtomPub protocol as an Controller with a set of custom ActionResults. That worked until I tried to get authentication working, when I realized that getting Basic or Digest auth (necessary for WLW) to work within my Forms-Auth based MVC app was going to be problematic.

我正在构建一个简单的ASP。NET MVC 2.0 web应用程序。我想提供一个AtomPub端点,这样我就可以从Windows Live Writer中发布/更新内容。我最初使用一组定制的ActionResults作为控制器实现AtomPub协议。直到我尝试让身份验证工作时,我才意识到在基于form - auth的MVC应用程序中使用Basic或Digest auth (WLW必需的)是有问题的。

So, now I've decided to move the AtomPub logic to a WCF service within the MVC app. I created a new WCF service called AtomPub.svc. I added the following to my web.config file:

现在,我决定将AtomPub逻辑移到MVC应用程序中的WCF服务中。我在网上添加了以下内容。配置文件:

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

And, my AtomPub.svc.cs code behind looks like this:

和,我的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;
        }
    }
}

I also added a route exclusion to exclude this endpoint from MVC's route handling.

我还添加了一个路由排除,将这个端点排除在MVC的路由处理中。

Now, I'm a total noob to WCF, so I'm sure I'm doing a number of things wrong. As I'm writing this, the root of the endpoint seems to be working as I get an AtomPub Service page. The URL templating, however, is not working and I don't know what to do to get it working. I'd love to hear your suggestions.

我是WCF的新手,所以我肯定我做错了很多事情。当我写这篇文章时,端点的根似乎在我获得AtomPub服务页面时工作。然而,URL模板没有工作,我不知道如何使它工作。我很想听听你的建议。

By the way, I'm trying to keep this overall implementation as simple as possible. So, I'm not looking to introduce a dependency on the Entity Framework so I can use WCF Data Services. I'd also prefer not to move the WCF endpoint into a separate project, though I'm open to that if I can easily deploy it to a W2k3/IIS6 environment.

顺便说一下,我试图使这个整体实现尽可能简单。因此,我不打算引入对实体框架的依赖,以便使用WCF数据服务。我也不希望将WCF端点移动到一个单独的项目中,尽管如果我可以轻松地将其部署到W2k3/IIS6环境中,我对此持开放态度。

1 个解决方案

#1


1  

OK, I found this article: RESTful WCF Services with No svc file and No config and it's pretty much gotten me up and working.

好的,我找到了这篇文章:RESTful WCF服务,它没有svc文件,也没有配置,这让我很兴奋。

#1


1  

OK, I found this article: RESTful WCF Services with No svc file and No config and it's pretty much gotten me up and working.

好的,我找到了这篇文章:RESTful WCF服务,它没有svc文件,也没有配置,这让我很兴奋。