2

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

私の質問は、Orchard のすべてのモジュールが本当にエリアのものであるということです。では、エリア/モジュールで作成された svc ファイルにヒットするルートを構築するにはどうすればよいでしょうか?

完全な物理パスを使用して svc ファイルにアクセスする必要があります (それを試したところ、サイトとエリアをブリッジしていたため、web.config の問題が発生しました)。

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

または、WebServiceHostFactory/OrchardServiceHostFactory を使用して ServiceRoute を作成しますか?

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

リソースにアクセスしようとすると、何を試しても404が返されます。wcfアプリケーションプロジェクトを使用してこれを機能させ、WCFをスタンドアロンアプリケーションとして設定することができました.Orchard/MVCに持ち込もうとしたときに問題が発生しました.

アップデート

助けてくれてありがとう

これは、サービスを実装するために行った手順です。

Routes.cs

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

WebServiceHostFactory() の代わりに OrchardServiceHostFactory() を使用すると、次のエラーが発生します。

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

オーチャード ルート 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>

マイサービス

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

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

モジュールの web.config を変更しただけでは、サービスを機能させることができませんでした。次のエラーが表示されます

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

更新 2

オーチャード ルート Web.Config

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

Routes.cs

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

                     }
                 };
}

これは機能します。ここで重要なのは、IDependency を参照しているオブジェクトで typeof を呼び出す必要があることです。WorkContextModule.IsClosingTypeOf は、依存関係を消費するオブジェクトを処理できず、直接呼び出されるインターフェイスを取得する必要があります。

4

1 に答える 1

2

あなたが述べたように、Orchard モジュールは ASP.NET MVC 用語の領域であるため、指定した URL は正しくなく、次のようにする必要があります。

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

localhostはアプリが実行される仮想ディレクトリであり、/WebServicesはモジュールのルートにあるフォルダーです。

プログラムでサービス ルートを問題なく作成することもできます。この記事では、Orchard に新しいルートを追加する方法について説明します。デフォルトの MVC ルートの代わりにServiceRouteをRouteDescriptor のRouteプロパティに割り当てることができます (ドキュメントに示されているように)。エリア対応の ASP.NET MVC アプリに ServiceRoute を追加することについての質問は以前に尋ねられました。

ところで-プレフィックス付きのサービスルートに関するこのSOの質問も確認できます。

HTH

于 2011-04-26T20:13:11.267 に答える