2

我正在使用 Castle WCF Integration Facility,并且我的第一个 webHttp 端点的一切工作正常。要使此端点工作,它要求端点启用了 WebHttpBehavior。我能够使用以下方法实现这一目标:

           container.Register(Component.For<IEndpointBehavior>()
                            .ImplementedBy<WebHttpBehavior>());

当我尝试使用与 WebHttpBehavior 不兼容的 BasicHttpBinding 启用第二个端点时,这会成为一个问题。

有没有办法指定上面的 IEndPointBehavior 注册只适用于某个端点?

这是我的服务的完整安装程序:

           container.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                 .Register(Component.For<IDiagnosticService>()
                    .ImplementedBy<DiagnosticService>()
                    .Named("DiagnosticService")
                    .LifestyleTransient()
                    .AsWcfService(new DefaultServiceModel()
                                    .Hosted()
                                    .AddEndpoints(WcfEndpoint.BoundTo(new WebHttpBinding()).At("json"))
                                    .AddEndpoints(WcfEndpoint.BoundTo(new BasicHttpBinding()).At("soap"))
                                    .PublishMetadata(o => o.EnableHttpGet())));


            container.Register(Component.For<IEndpointBehavior>()
                            .ImplementedBy<WebHttpBehavior>());
4

1 回答 1

3

好的。我终于想通了。事实证明,我的大部分问题都与 Azure 仿真环境有关,而不是与 Castle WCF 集成有关。答案很简单——只需设置 ServiceEndpoint 实例并使用 WcfEndpoint.FromEndpoint() 方法。

这是我的工作安装程序:

        String internalEndpointAddress = string.Format("http://{0}/DiagnosticService.svc", 
                                           RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint);

        // This ContractDescription instance must be used for both endpoints in this case
        ContractDescription description = ContractDescription.GetContract(typeof(IDiagnosticService));

        // Create JSON webHTTP Binding            
        WebHttpBinding webhttpbinding = new WebHttpBinding();
        string jsonURI = internalEndpointAddress + "/json";
        EndpointAddress jsonEndpointAddress = new EndpointAddress(new Uri(jsonURI));
        ServiceEndpoint jsonEndpoint = new ServiceEndpoint(description, webhttpbinding, jsonEndpointAddress);
        jsonEndpoint.Behaviors.Add(new WebHttpBehavior());


        // Create WSHTTP Binding          
        WSHttpBinding wsHttpBinding = new WSHttpBinding();
        string soapURI = internalEndpointAddress + "/soap";
        EndpointAddress soapEndpointAddress = new EndpointAddress(new Uri(soapURI));
        ServiceEndpoint soapEndpoint = new ServiceEndpoint(description, wsHttpBinding, soapEndpointAddress);



        container.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                 .Register(Component.For<IDiagnosticService>()
                    .ImplementedBy<DiagnosticService>()
                    .Named("DiagnosticService")
                    .LifestyleTransient()
                    .AsWcfService(new DefaultServiceModel()
                                    .Hosted()
                                    .AddEndpoints(WcfEndpoint.FromEndpoint(jsonEndpoint))
                                    .AddEndpoints(WcfEndpoint.FromEndpoint(soapEndpoint))
                                    .PublishMetadata(o => o.EnableHttpGet())));
于 2012-08-01T21:10:41.413 回答