果园/ MVC WCF服务的URL与区 [英] Orchard/MVC WCF Service Url with Area

查看:118
本文介绍了果园/ MVC WCF服务的URL与区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伯特兰创建了一个博客的帖子指定如何使用国际奥委会WCF模块果园。

Bertrand created a blog post to specify how to use IoC in WCF Modules for Orchard.

在1.1中,你可以使用新的果园主机厂建立一个SVC文件:

In 1.1, you can create a SVC file using the new Orchard host factory:

<%@ 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);
    }
}

我的问题是,所有果园的模块是真正的地区。所以你怎么能构建命中面积/模块中创建的SVC文件的路径?

My question is that all of Orchard's modules are really area's. So how can you build a route that hits the svc file created in the area/module?

如果您使用完整的物理路径去的SVC文件(尝试,和它造成一个web.config问题,因为它是弥合站点和区域)。

Should you use the full physical path to get to the svc file (tried that and it caused a web.config issue since it was bridging a site and area).

http://localhost/modules/WebServices/MyService.svc

还是你创建WebServiceHostFactory / OrchardServiceHostFactory?

Or do you create a ServiceRoute with WebServiceHostFactory/OrchardServiceHostFactory?

new ServiceRoute("WebServices/MyService", new OrchardServiceHostFactory(), typeof(MyService))

无论我尝试,我得到一个404试图击中资源时。我能得到使用WCF应用程序项目和设置WCF作为独立的应用程序这方面的工作,我的问题,试图把它变成果园/ MVC的时候开始了。

Whatever I try I get a 404 when trying to hit the resource. I was able to get this working using a wcf Application project and setting WCF as a stand alone application, my issues started when trying to bring it into Orchard/MVC.

更新

感谢您的帮助彼得,

这是我接过来实现服务的步骤。

This is the steps I took to implement the service.

Routes.cs

Routes.cs

new RouteDescriptor {   Priority = 20,
                        Route = new ServiceRoute(
                                      "Services",
                                      new WebServiceHostFactory(),
                                      typeof(MyService)) }

如果我使用OrchardServiceHostFactory()而不是WebServiceHostFactory()我得到以下错误。

If I use OrchardServiceHostFactory() instead of WebServiceHostFactory() I get the following error.

Operation is not valid due to the current state of the object.

果园根web.config

Orchard Root 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>

为MyService

MyService

[ServiceContract]
public interface IMyService : IDependency
{
    [OperationContract]
    string GetTest();
}

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
class MyService : IMyService
{
    public string GetTest()
    {
        return "test";
    }
}

我无法得到服务,只需修改模块的web.config工作。我收到以下错误

I couldn't get the service working by just modifying the module's web.config. I get the following error

ASP.NET routing integration feature requires ASP.NET compatibility.

更新2

果园根web.config

Orchard Root Web.Config

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <!-- ... -->
  </system.serviceModel>

Routes.cs

Routes.cs

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

                     }
                 };
}

这工作的,这里的关键是,你必须调用的typeof被引用IDependency,WorkContextModule.IsClosingTypeOf不能处理,消耗的依赖关系对象的对象,它必须采取它直接调用接口。

This works, the key here is that you must call typeof on the object that is referencing IDependency, WorkContextModule.IsClosingTypeOf cant handle the object that consumes the dependancy, it must take the Interface that it is directly called by.

推荐答案

正如你所说,果园模块在ASP.NET MVC方面的区域,所以你提供的网址是不正确的,应该是:

As you stated, Orchard modules are areas in ASP.NET MVC terms, so the URL you provided is incorrect and should be:

http://localhost/Your.Orchard.Module/WebServices/MyService.svc

其中的本地主机的是虚拟目录下,你的应用程序运行和 / Web服务的是你的模块的根文件夹。

Where localhost is the virtual directory under which your app runs and /WebServices is a folder in the root of your module.

您也可以编程方式创建一个服务路线没有问题。 本文讲述如何添加新航线在果园。你可以指定一个 ServiceRoute 路线 RouteDescriptor的属性,而不是默认的MVC的路由(如文档所示)。
<一href=\"http://stackoverflow.com/questions/4047485/expose-wcf-services-that-belong-to-an-area-in-mvc-app-at-a-routed-path\">The问题了解中启用了区域的ASP.NET MVC应用程序添加ServiceRoute被问过,检查出来,因为它可以帮助你。

You can also create a service route programatically without problem. This article tells how to add new routes in Orchard. You can just assign a ServiceRoute to the Route property of a RouteDescriptor instead of a default MVC route (as shown in docs). The question about adding ServiceRoute in area-enabled ASP.NET MVC app was asked before, check it out as it may help you out.

顺便说一句 - 你也可以检查<一个href=\"http://stackoverflow.com/questions/3186858/can-a-wcf-serviceroute-route-$p$pfix-contain-a-path-value\">this SO质疑约prefixed服务航线。

Btw - You may also check this SO question about prefixed service routes.

心连心

这篇关于果园/ MVC WCF服务的URL与区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆