Bertrand創建了一個博客post來指定如何在WCF模塊中爲Orchard使用IoC。Orchard/MVC WCF服務與區域網址
在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應用程序項目並將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.
更新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不能處理消耗依賴性的對象,它必須接受它直接調用的接口。
嘗試更改* RequirementsMode *從* Allowed *改爲* Required *您的服務類。我會試着調查是什麼造成這個問題。 – 2011-04-27 16:38:49
同樣的問題。如果您想查看示例模塊並親自查看錯誤,請在https://bitbucket.org/e2software/orchardwcf創建一個hg存儲庫。 – 2011-04-27 18:37:20
我想這個問題是因爲你的服務實現被標記爲* internal *。嘗試使* public *,它應該工作,而不需要這種類型(IMyService)黑客。內部方法對底層DI引擎是不可見的,它們只是被忽略... – 2011-04-28 02:19:48