2

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 ルーティングを使用しているため、アプリケーションには 1 つもありません。

したがって、私の 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 で実装してみることをお勧めしますか?

4

1 に答える 1