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 は、依存関係を消費するオブジェクトを処理できず、直接呼び出されるインターフェイスを取得する必要があります。