Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将unity.wcf与asp.net路由集成_C#_.net_Wcf_Unity Container - Fatal编程技术网

C# 将unity.wcf与asp.net路由集成

C# 将unity.wcf与asp.net路由集成,c#,.net,wcf,unity-container,C#,.net,Wcf,Unity Container,我试图在没有svc文件的wcf web服务中使用unity.wcf 我的代码: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]

我试图在没有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>();


    }
}
当我调用我的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来实现吗?

好的,我已经通过以下链接找到了答案

我必须创建一对新的类来继承WebServiceHostFactory(抽象)和WebServiceHost,如链接中所述

一旦这些都准备好了,我的ServiceFactory类继承了新类,一切都开始工作了

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