使用WCFFacility为托管服务提供两个WS / Rest端点

时间:2013-02-01 10:32:47

标签: c# wcf castle-windsor wcffacility

我们正在使用WCFFacility从托管(IIS 7.5)环境设置服务。 我们需要的是为每个服务提供两个端点,.NET客户端的WSHttp和其他所有人的WebHttp。这可能吗?

我们使用的代码:

_container.Register(
    Component
        .For<ISomeService>()
        .ImplementedBy<SomeService>()
        .AsWcfService(new DefaultServiceModel()
        .Hosted()
        .PublishMetadata(mex => mex.EnableHttpGet())
        .AddEndpoints(
            WcfEndpoint.BoundTo(new WSHttpBinding()).At("v1/ws"),
            WcfEndpoint.BoundTo(new WebHttpBinding()).At("v1/rest")
        ))
    );

然后:

RouteTable.Routes.Add(new ServiceRoute("", new DefaultServiceHostFactory(_container.Kernel), typeof(ISomeService)));

我认为我们不能真正混合使用ws / web端点,但这可以通过其他方式实现吗?我们不希望回退到xml配置,但我们需要配置端点。

1 个答案:

答案 0 :(得分:1)

经过一整天的挖掘和尝试后,我找到了解决方案。除了最终获得帮助/ wsdl页面之外,没有以任何方式进行测试。所以我暂时搁置这个问题。

_container.Register(
    Component
    .For<ISomeService>()
    .ImplementedBy<SomeService>()
    .AsWcfService(new RestServiceModel().Hosted())
    .AsWcfService(new DefaultServiceModel().Hosted()
        .PublishMetadata(mex => mex.EnableHttpGet())
        .AddEndpoints(
            WcfEndpoint.ForContract<ISomeService>().BoundTo(new WSHttpBinding())
        )
    )
);

RouteTable.Routes.Add(new ServiceRoute("v1/rest", new WindsorServiceHostFactory<RestServiceModel>(_container.Kernel), typeof(ISomeService)));
RouteTable.Routes.Add(new ServiceRoute("v1/ws", new WindsorServiceHostFactory<DefaultServiceModel>(_container.Kernel), typeof(ISomeService)));
相关问题