Castle WCF客户端注册语法 [英] Castle WCF Client Registration syntax

查看:73
本文介绍了Castle WCF客户端注册语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在Castle WcfIntegration 3.0中注册WCF客户端;以下语法有什么问题吗?

Trying to register a WCF client with Castle WcfIntegration 3.0; is there anything wrong with the following syntax?

Container.Kernel.Register(Component.For(serviceType).AsWcfClient(new DefaultClientModel {Endpoint = WcfEndpoint .FromConfiguration(serviceType。 Name。Substring(1)+ Client)}).LifeStyle.Is(lifestyle));

Container.Kernel.Register( Component.For(serviceType) .AsWcfClient(new DefaultClientModel { Endpoint = WcfEndpoint .FromConfiguration( serviceType.Name. Substring(1) + "Client") }) .LifeStyle.Is(lifestyle));

我遇到的问题是WCF服务操作ServiceSecurityContext.Current为null。在旧版本的Castle(1.0.3.0)中没有发生这种情况。尝试了解这是我做错的事情还是对Castle的某些更改要求进行其他更改以使ServiceSecurityContext.Current像以前一样进行填充。

The problem I'm having is when in the context of a WCF service operation, ServiceSecurityContext.Current is null. This did not happen in the old version of Castle (1.0.3.0). Trying to understand if it's something I'm doing wrong or if some change to Castle mandates some other change to get ServiceSecurityContext.Current to populate as it did before.

谢谢

推荐答案

记录下来,这是我最后使用的语法。 (鉴于需要更多的Castle文档,我认为使用语法的任何示例都不会受到伤害)!

For the record, here is the syntax I used that worked in the end. (Given the need for more Castle documentation, I figure any example of working syntax couldn't hurt)!

Container.Kernel.Register(Component.For(serviceType)
            .LifeStyle.Is(lifestyle)
            .DependsOn(new
            {
                clientModel = new DefaultClientModel
                {
                    Endpoint = WcfEndpoint
                    .FromConfiguration(serviceType.Name.Substring(1) + "Client")
                }
            }));

同样,ServiceSecurityContext.Current为空的问题是出于不同的原因。

Also for the record, the problem of the ServiceSecurityContext.Current being null was happening for a different reason.

我对配置文件进行了更改,我认为这是微不足道的(因为某些类似乎已过时),但事实证明它非常重要(并且这些类非常需要)。

I had made a change to a config file, which I thought was insignificant (because certain classes appeared to be obsolete), but which turned out to be very significant (and those classes were very much needed).

城堡配置文件中的 component节点如下所示:

The "component" node in the castle config file looked like this:

<component id="FederatedServiceHostBuilder"
           service="Castle.Facilities.WcfIntegration.IServiceHostBuilder`1[[Castle.Facilities.WcfIntegration.DefaultServiceModel, 
           Castle.Facilities.WcfIntegration, Version=3.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc]], Castle.Facilities.WcfIntegration"
           type="OurCustomer.Framework.Service.Security.FederatedServiceHostBuilder, OurCustomer.Framework.Service"
           lifestyle="Transient">
  <interceptors>
    <interceptor>${InstrumentationInterceptor}</interceptor>
  </interceptors>
</component>

FederatedServiceHostBuilder类:

The "FederatedServiceHostBuilder" class:

/// <summary>
/// The default implementation of <see cref="IServiceHostBuilder{M}"/>.
/// </summary>
public class FederatedServiceHostBuilder : AbstractServiceHostBuilder<DefaultServiceModel>
{
    /// <summary>
    /// Constructs a new <see cref="FederatedServiceHostBuilder"/>.
    /// </summary>
    /// <param name="kernel">The kernel.</param>
    public FederatedServiceHostBuilder(IKernel kernel)
        : base(kernel)
    {
    }

    #region AbstractServiceHostBuilder Members
    /// <summary>
    /// 
    /// </summary>
    /// <param name="model"></param>
    /// <param name="serviceModel"></param>
    /// <param name="baseAddresses"></param>
    /// <returns></returns>
    protected override ServiceHost CreateServiceHost(ComponentModel model,
                                                     DefaultServiceModel serviceModel,
                                                     params Uri[] baseAddresses)
    {
        return CreateServiceHost(model, GetEffectiveBaseAddresses(serviceModel, baseAddresses));
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="model"></param>
    /// <param name="baseAddresses"></param>
    /// <returns></returns>
    protected override ServiceHost CreateServiceHost(ComponentModel model,
                                                     params Uri[] baseAddresses)
    {
        return new FederatedServiceHost(model, baseAddresses);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="serviceType"></param>
    /// <param name="baseAddresses"></param>
    /// <returns></returns>
    protected override ServiceHost CreateServiceHost(Type serviceType,
                                                     params Uri[] baseAddresses)
    {
        return new FederatedServiceHost(serviceType, baseAddresses);
    }

    #endregion
}

(关键)FederatedServiceHost类:

and the (crucial) FederatedServiceHost class:

public class FederatedServiceHost : Castle.Facilities.WcfIntegration.DefaultServiceHost
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="model"></param>
    /// <param name="baseAddresses"></param>
    public FederatedServiceHost(ComponentModel model, params Uri[] baseAddresses)
        : base(model, baseAddresses)
    {
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="serviceType"></param>
    /// <param name="baseAddresses"></param>
    public FederatedServiceHost(Type serviceType, params Uri[] baseAddresses)
        : base(serviceType, baseAddresses)
    {
    }

    /// <summary>
    /// <remarks />
    /// </summary>
    protected override void OnOpening()
    {
        FederatedServiceCredentials.ConfigureServiceHost(this);
        base.OnOpening();
    }
}

因此,最重要的是,它是 FederatedServiceCredentials .ConfigureServiceHost(this)行丢失,导致我的ServiceSecurityContext.Current为空。

So the bottom line is, it was the "FederatedServiceCredentials.ConfigureServiceHost(this)" line that was missing, and thus causing my ServiceSecurityContext.Current to be null.

这篇关于Castle WCF客户端注册语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆