【问题标题】:Castle WcfFacility - Service BehaviorsCastle WcfFacility - 服务行为
【发布时间】:2010-04-23 12:13:57
【问题描述】:

如何使用 Castle WcfFacility 并让它使用标准的 Wcf 配置文件设置?

如果我这样注册:

container.Register(
AllTypes.Pick()
    .FromAssemblyNamed("{ServicesAssembly}") // <-- service assembly here
    .If(type => type.Name.EndsWith("Service"))
    .WithService.FirstInterface()
    .Configure(configurer => configurer.LifeStyle.Transient)
    .Configure(configurer => configurer.Named(configurer.Implementation.Name))
    .Configure(configurer => configurer.ActAs(new DefaultServiceModel()))
);

我收到以下错误:

服务“{name}”有零个应用程序(非基础设施)端点。

如果我离开:

.Configure(configurer => configurer.ActAs(new DefaultServiceModel()))

似乎配置中的行为被忽略了。

这里的正确用法是什么?

【问题讨论】:

    标签: wcf castle-windsor facilities


    【解决方案1】:

    好的,想通了:)

    我是这样注册的:

    container.Register(
    AllTypes.Pick()
        .FromAssemblyNamed("{ServicesAssembly}") // <-- service assembly here
        .If(type => type.Name.EndsWith("Service"))
        .WithService.FirstInterface()
        .Configure(configurer => configurer.LifeStyle.Transient)
        .Configure(configurer => configurer.Named(configurer.Implementation.Name))
        .Configure(configurer => configurer.ActAs(new DefaultServiceModel().Hosted()))
    );
    

    Hosted() 用于表明我正在托管服务; else 似乎 WCF 设施会尝试托管它们,从而导致端口冲突。

    所以问题是配置文件中服务的名称必须是实现的完整类型名称。如果没有人收到错误,说明没有定义端点。所以服务名称不与windsor中指定的名称相同。

    【讨论】:

      【解决方案2】:

      你快到了。

      你需要这个:

      .ActAs(new DefaultClientModel(WcfEndpoint.FromConfiguration( <<key In Configuration>> )));
      

      【讨论】:

      • 谢谢...但是:) --- 这是服务端(DefaultServiceModel)。如何在服务器端做到这一点?另外,那个“键”是什么(可能是服务的名称)?
      • key 是配置键,很可能是类型名称,除非您在 ServiceBehaviorAttribute 上指定了 ConfigName 到其他地方。 DefaultServiceModel不能也这样用吗?
      • 不。有一个 AddEndpoints 方法,但使用 Wcf.FromConfiguration 会导致错误:无法从端点名称创建 ServiceHost 的 ServiceEndpoint。
      • 嗯,这很有趣。我建议你在 Castle 用户讨论组中提出这个问题。也许这是一个缺失的功能... WCF 工具尚未发布,因此它可能没有所需的一切。
      猜你喜欢
      • 2013-12-10
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      • 2010-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多