使用ServiceRoute的Orchard CMS WCF服务

时间:2012-05-16 11:14:11

标签: web-services orchardcms

我已经配置了Orchard模块来公开服务并启用了它。我无法根据以下内容计算出要使用的URL。

Routes.cs

namespace OrchardRestService
{
    using System.Collections.Generic;
    using System.ServiceModel.Activation;

    using Orchard.Mvc.Routes;
    using Orchard.Wcf;

    public class Routes : IRouteProvider
    {
        #region Implementation of IRouteProvider

        public IEnumerable<RouteDescriptor> GetRoutes()
        {
            return new[] {
                new RouteDescriptor {
                   Priority = 20,
                        Route = new ServiceRoute(
                                      "ContentService",
                                      new OrchardServiceHostFactory(),
                                      typeof(IContentService))
                }
            };
        }

        public void GetRoutes(ICollection<RouteDescriptor> routes)
        {
            foreach (var routeDescriptor in GetRoutes())
                routes.Add(routeDescriptor);
        }

        #endregion
    }
}

IContentService.cs:

namespace OrchardRestService
{
    using System.ServiceModel;

    using Orchard;

    [ServiceContract]
    public interface IContentService : IDependency
    {
        [OperationContract]
        ContentResult GetContent(string contentPath);
    }
}

ContentService.cs:

namespace OrchardRestService
{
    using System.Collections.Generic;
    using System.ServiceModel.Activation;

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ContentService : IContentService
    {
        public ContentResult GetContent(string contentPath)
        {
            var contentResult = new ContentResult
                { ContentValues = new Dictionary<string, string>(), Found = true, Path = contentPath };
            return contentResult;
        }
    }
}

我试图遵循Bertrand Le Roy写的herehere,但似乎错过了什么。

我的代码是.Net 4,所以不需要SVC文件。

1 个答案:

答案 0 :(得分:1)

关闭,因为我正在跳过篮球以这种方式使用N2而不是它的设计目的。