[英]integrating unity.wcf with asp.net routes
我正在嘗試在沒有svc文件的wcf Web服務中使用unity.wcf。
我的代碼:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
//[BasicAuthentication] TODO: this need to be set up
public class SsoAuthenticationService : ISsoAuthenticationService
{
private readonly ICustomerManager _manager;
internal const string ServiceUri = "SsoAuthenticationService";
public SsoAuthenticationService(ICustomerManager manager)
{
_manager = manager;
}
[WebGet(UriTemplate = "CreateSsoLogin/{request}")]
public ServiceResponse<bool> CreateSsoLogin(string request)
{
// TODO: inputs and outputs are wrong
_manager.DoWork();
return new ServiceResponse<bool>();
}
}
public class ServiceFactory : UnityServiceHostFactory
{
protected override void ConfigureContainer(Microsoft.Practices.Unity.IUnityContainer container)
{
container.RegisterType<ISsoAuthenticationService, SsoAuthenticationService>("authentication")
.RegisterType<ICustomerManager, CustomerManager>();
}
}
現在,問題出在我嘗試連接ServiceFactory類時-在所有代碼示例中,我都看到它們通過svc文件完成此操作,但是我的應用程序中沒有該文件,因為它使用的是ASP.NET路由。
所以我的Global.asax看起來像:
private static void RegisterRoutes(RouteCollection routes)
{
//Integrate WCF services with the ASP.NET routing feature
routes.Add(new ServiceRoute(SsoAuthenticationService.ServiceUri, new ServiceFactory(), typeof(SsoAuthenticationService)));
}
當我調用Web服務方法時,我沒有點擊Web方法代碼(盡管確實調用了ServiceFactory.ConfigureContainer)。 如果我不使用Unity,則Global.asax將如下所示:
private static void RegisterRoutes(RouteCollection routes)
{
//Integrate WCF services with the ASP.NET routing feature
routes.Add(new ServiceRoute(SsoAuthenticationService.ServiceUri, new WebServiceHostFactory(), typeof(SsoAuthenticationService)));
}
如果將其更改為此,則將調用web方法,但當然會抱怨構造函數。
我需要什么額外的配置才能使ServiceFactory類像WebServiceHostFactory一樣工作?
還是更好的選擇是不使用Unity.Wcf,並嘗試使用純Unity來實現?
好的,我已經設法通過以下鏈接找到了答案:http://www.agile-code.com/blog/rest-web-services-with-unity-wcf/
我必須創建一對新的類以從WebServiceHostFactory(抽象)和WebServiceHost繼承,如鏈接中所述。
一旦這些就位,並且我的ServiceFactory類從新類繼承,一切就開始起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.