【问题标题】:Specifying Castle WCF Integration Facility Endpoint Behavior per Endpoint指定每个端点的 Castle WCF 集成设施端点行为
【发布时间】:2012-07-31 22:04:55
【问题描述】:

我正在使用 Castle WCF 集成工具,并且我的第一个 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>());

【问题讨论】:

  • WcfEndpoint 类接受 System.ServiceModel.ServiceEndpoint 的实例。使用它,我可以根据需要独立配置端点。这似乎工作正常,但我无法弄清楚如何处理相对寻址(即(local/ser.svc/json vs (local/ser.svc/soap) System.ServiceModel.EndpointAddress 的构造函数需要一个 URI。如果我把整个 uri (@987654323 @),我得到一个“没有协议绑定匹配”异常。如果我只使用 local/ser.svc 作为 URI,它可以工作,但我没有 /json 和 /soap 端点地址。

标签: wcf integration behavior castle endpoint


【解决方案1】:

好的。我终于想通了。事实证明,我的大部分问题都与 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())));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多