3

WcfFacility1 つのサービスと IISを使用して複数のサービスをホストしようとしていますが、混乱する結果がいくつか見られます。

これが私の構成です:

        var baseUri = new Uri(HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped));

        container.AddFacility<WcfFacility>(f => { f.CloseTimeout = TimeSpan.Zero; }).Register(
            Component.For<IAttributeService>()                  
                .ImplementedBy<AttributeService>()
                .AsWcfService(
                    new DefaultServiceModel()
                        .Hosted()                           
                        .AddEndpoints(
                            WcfEndpoint.ForContract<IAttributeService>().BoundTo(new BasicHttpBinding()).At("Soap11"),
                            WcfEndpoint.ForContract<IAttributeService>().BoundTo(new WSHttpBinding()).At("Soap12")
                        )
                .AddBaseAddresses(new Uri(baseUri, "AttributeService.svc"))                 
                ),                      
            Component.For<ISessionService>()
                .ImplementedBy<SessionService>()
                .AsWcfService(
                    new DefaultServiceModel()
                        .Hosted()                           
                        .AddEndpoints(
                            WcfEndpoint.ForContract<ISessionService>().BoundTo(new BasicHttpBinding()).At("Soap11"),
                            WcfEndpoint.ForContract<ISessionService>().BoundTo(new WSHttpBinding()).At("Soap12")
                        )
                .AddBaseAddresses(new Uri(baseUri, "SessionService.svc"))
                ),          
            Component.For<ISampleService>()
                .ImplementedBy<SampleService>()
                .AsWcfService(
                    new DefaultServiceModel()
                        .Hosted()
                        .AddEndpoints(
                            WcfEndpoint.ForContract<ISampleService>().BoundTo(new BasicHttpBinding()).At("Soap11"),
                            WcfEndpoint.ForContract<ISampleService>().BoundTo(new WSHttpBinding()).At("Soap12")
                        )
                .AddBaseAddresses(new Uri(baseUri, "SampleService.svc"))
                )
        );

これを確認するために WCF テスト クライアントを使用すると、各サービスで使用できるメソッドは、そのサービスとその前に作成したすべてのサービスを組み合わせたものであるかのように見えます。例: WCF テスト クライアントでサービスを確認する

私はこれを間違っていますか?複数回追加することはできずWcfFacility、インターネットを調べてみると、誰かが 1 つの施設で複数のサービスをホストしている例が見つからないようです。

何か案は?

4

1 に答える 1

9

私はそれを理解しました。以前は、次のコードを使用して MetaData で HttpGet を有効にしていました。

var metadata = new ServiceMetadataBehavior { HttpGetEnabled = true };
container.Register(Component.For<IServiceBehavior>().Instance(metadata));

これは、この github exampleのコードに従っていました。

このアプローチにより、WcfFacility はすべての get 要求ですべてのサービスの MetaData を共有するように見えます。

解決策は簡単でした。まず、そのようなものを取り除きます。次に、この方法で各サービス コンポーネントを構成します。

Component.For<IAttributeService>()                  
.ImplementedBy<AttributeService>()
.AsWcfService(
    new DefaultServiceModel()
        .Hosted()
        .PublishMetadata(x => x.EnableHttpGet())
        .AddBaseAddresses(new Uri(baseUri, "AttributeService.svc"))             
        .AddEndpoints(
            WcfEndpoint.ForContract<IAttributeService>().BoundTo(new BasicHttpBinding()).At("Soap11"),
            WcfEndpoint.ForContract<IAttributeService>().BoundTo(new WSHttpBinding()).At("Soap12")
        )                               
),

具体的には、.PublishMetadata(x => x.EnableHttpGet())すべてのコンポーネントにこのコードを追加するのがコツでした。

これで、各サービスで期待される動作が見られます。

予想される動作! わーい!

編集:機能するようになったら、必要な場合とそうでない場合があるものを削除する作業に取り掛かりました-構成よりも慣習が大好きです。これが結果です。他に取り去るものはないようです。これの良いところは、サービスごとに 1 つの登録を必要とするのではなく、すべてのサービスの一般的な登録にさらにリファクタリングできることです。商品を共有するだけです。

        Component.For<IAttributeService>()
            .ImplementedBy<AttributeService>()
            .AsWcfService(
                new DefaultServiceModel()
                    .Hosted()
                    .PublishMetadata(x => x.EnableHttpGet())
                    .AddEndpoints(
                        WcfEndpoint.BoundTo(new BasicHttpBinding()).At("Soap11"),
                        WcfEndpoint.BoundTo(new WSHttpBinding()).At("Soap12")
                    )
        ),

そして、これが一般的な登録です。

Classes.FromThisAssembly()
.Where(t => Attribute.IsDefined(t, typeof(StandardServiceAttribute)))
.WithService.Select((t, _) => t.GetInterfaces().Where(i => Attribute.IsDefined(i, typeof(ServiceContractAttribute),false)))
.Configure
(cr => 
    cr.AsWcfService(
        new DefaultServiceModel()
            .Hosted()
            .PublishMetadata(x => x.EnableHttpGet())
            .AddEndpoints(
                WcfEndpoint.BoundTo(new BasicHttpBinding()).At("Soap11"),
                WcfEndpoint.BoundTo(new WSHttpBinding()).At("Soap12")                       
            )
        )
)
于 2012-03-16T15:31:02.170 に答える