Asp.net 带区域的Orchard/MVC WCF服务Url

Asp.net 带区域的Orchard/MVC WCF服务Url,asp.net,asp.net-mvc,wcf,rest,orchardcms,Asp.net,Asp.net Mvc,Wcf,Rest,Orchardcms,Bertrand创建了一个博客,指定如何在Orchard的WCF模块中使用IoC 在1.1中,可以使用新的Orchard主机工厂创建SVC文件: <%@ ServiceHost Language="C#" Debug="true" Service="MyModule.IMyService, MyAssembly" Factory="Orchard.Wcf.OrchardServiceHostFactory, Orchard.Framework" %> Then re

Bertrand创建了一个博客,指定如何在Orchard的WCF模块中使用IoC

在1.1中,可以使用新的Orchard主机工厂创建SVC文件:

<%@ ServiceHost Language="C#" Debug="true" 
    Service="MyModule.IMyService, MyAssembly"
    Factory="Orchard.Wcf.OrchardServiceHostFactory, Orchard.Framework" %>
Then register your service normally as an IDependency but with service and operation contract attributes:

using System.ServiceModel;

namespace MyModule {
    [ServiceContract]
    public interface IMyService : IDependency {
        [OperationContract]
        string GetUserEmail(string username);
    }
}
或者您是否使用WebServiceHostFactory/OrchardServiceHostFactory创建ServiceRoute

new ServiceRoute("WebServices/MyService", new OrchardServiceHostFactory(), typeof(MyService))
无论我尝试什么,当我尝试点击资源时,我都会得到一个404。我使用一个wcf应用程序项目并将wcf设置为一个独立的应用程序来实现这一点,我的问题是从尝试将其引入Orchard/MVC时开始的

更新

谢谢你的帮助Piotr

这是我实现该服务所采取的步骤

Routes.cs

new RouteDescriptor {   Priority = 20,
                        Route = new ServiceRoute(
                                      "Services",
                                      new WebServiceHostFactory(),
                                      typeof(MyService)) }
public IEnumerable<RouteDescriptor> GetRoutes() {
    return new[] {
                     new RouteDescriptor {   Priority = 20,
                                             Route = new ServiceRoute(
                                                 "Services",
                                                 new OrchardServiceHostFactory(),
                                                 typeof(IMyService))

                     }
                 };
}
如果使用OrchardServiceHostFactory()而不是WebServiceHostFactory(),则会出现以下错误

Operation is not valid due to the current state of the object.
Orchard根Web.Config

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>
        <!-- 
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
            via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <!-- ... -->
  </system.serviceModel>
仅通过修改模块的web.config,我无法使服务正常工作。我得到以下错误

ASP.NET routing integration feature requires ASP.NET compatibility.
更新2

Orchard根Web.Config

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>
        <!-- 
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
            via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <!-- ... -->
  </system.serviceModel>

Routes.cs

new RouteDescriptor {   Priority = 20,
                        Route = new ServiceRoute(
                                      "Services",
                                      new WebServiceHostFactory(),
                                      typeof(MyService)) }
public IEnumerable<RouteDescriptor> GetRoutes() {
    return new[] {
                     new RouteDescriptor {   Priority = 20,
                                             Route = new ServiceRoute(
                                                 "Services",
                                                 new OrchardServiceHostFactory(),
                                                 typeof(IMyService))

                     }
                 };
}
public IEnumerable GetRoutes(){
返回新的[]{
新路由描述符{Priority=20,
路由=新服务路由(
“服务”,
新的OrchardServiceHostFactory(),
类型(IMyService))
}
};
}

这是可行的,这里的关键是您必须对引用IDEDependence的对象调用typeof,WorkContextModule.IsClosingTypeOf无法处理使用依赖性的对象,它必须使用直接调用它的接口。

如您所述,Orchard模块是ASP.NET MVC术语中的区域,因此,您提供的URL不正确,应该是:

http://localhost/Your.Orchard.Module/WebServices/MyService.svc
其中localhost是应用程序运行的虚拟目录,/WebServices是模块根目录中的文件夹

您还可以通过编程方式创建服务路线,而不会出现问题。本文介绍如何在Orchard中添加新路线。您只需将服务路由分配给RoutedDescriptor的路由属性,而不是默认的MVC路由(如文档中所示)。 关于在启用区域的ASP.NET MVC应用程序中添加ServiceRoute,请查看,因为它可能会帮助您解决问题

顺便说一句,您也可以检查有关前缀服务路线的问题


HTH

当我转到时,我得到一个错误,IControllerFactory“Orchard.Mvc.OrchardControllerFactory”没有返回名为“Data”的控制器。如果我在路由中使用OrchardServiceHostFactory,则由于对象的当前状态,我获取操作无效。但是WebServiceHostFactory工作正常。请尝试将服务类上的RequirementsMode从Allowed更改为RequirementsMode。我会尽力调查问题的原因。同样的问题。如果您想查看示例模块并直接看到错误,我在创建了一个hg存储库。尝试将其公开,它应该可以工作,而不需要那种类型的(IMyService)黑客。内部方法对于底层DI引擎是不可见的,它们只是被忽略了。。。