Bertrandは、オーチャードのWCFモジュールでIoCを使用する方法を指定するためにブログpostを作成しました。Orchard/MVC WCFサービスURL(エリアあり)
1.1では、新しいオーチャードホストファクトリを使用して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);
}
}
私の質問は、オーチャードのモジュールのすべてが本当に地域のあることです。だからどのように領域/モジュールで作成されたSVCファイルに当るルートを構築することができますか?
完全な物理パスを使用してsvcファイルにアクセスする必要があります(これを試みて、サイトと領域をブリッジしていたためweb.configの問題が発生しました)。
http://localhost/modules/WebServices/MyService.svc
それともWebServiceHostFactory/OrchardServiceHostFactoryとServiceRouteを作成するのですか?
new ServiceRoute("WebServices/MyService", new OrchardServiceHostFactory(), typeof(MyService))
私はリソースにヒットしようとすると404を取得します。私はwcf Applicationプロジェクトを使用してこれを動作させ、WCFをスタンドアロンアプリケーションとして設定することができました。問題はOrchard/MVCに持ち込もうとしたときに始まりました。ヘルプピョートルため
UPDATE
おかげで、
これは私がサービスを実装するために要した手順です。
Routes.cs
new RouteDescriptor { Priority = 20,
Route = new ServiceRoute(
"Services",
new WebServiceHostFactory(),
typeof(MyService)) }
私はOrchardServiceHostFactory()の代わりに、WebServiceHostFactory()を使用している場合は、私は次のエラーを取得します。
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>
たMyService
[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.
UPDATE 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は依存関係を消費するオブジェクトを処理できません。直接呼び出されるInterfaceを取る必要があります。
サービスクラスで* RequirementsMode *を* Allowed *から* Required *に変更してみてください。問題を抱えていることを調べようとします。 –
同じ問題。あなたがサンプルモジュールを見て、最初のエラーを見たいと思ったら、私はhttps://bitbucket.org/e2software/orchardwcfにhgリポジトリを作成しました。 –
サービスの実装が* internal *とマークされているため、問題があると思います。それをpublic *にしてみてください。それは、そのtypeof(IMyService)ハックを必要とせずに動作するはずです。内部メソッドは、基になるDIエンジンには見えず、無視されます。 –