zoukankan      html  css  js  c++  java
  • wcf 访问控制

    public class PasswordDigestChannelFactory<TPortTypeClient, TPlugin>
        where TPortTypeClient : ClientBase<TPlugin>, TPlugin, new()
        where TPlugin : class
    {
        public PasswordDigestChannelFactory(string endpointConfigurationName)
        {
            _endpointConfigurationName = endpointConfigurationName;
        }
    
        private readonly string _endpointConfigurationName;
    
        public TPlugin GetClient()
        {
            var args = new[] {_endpointConfigurationName};
            var portInstance = Activator.CreateInstance(typeof (TPortTypeClient), args) as ClientBase<TPlugin>;
            
            // replace ClientCredentials with UsernameClientCredentials
            var username = "username";
            var password = "password";
    
            var credentials = new UsernameClientCredentials(new UsernameInfo(username, password));
            portInstance.ChannelFactory.Endpoint.Behaviors.Remove(typeof (ClientCredentials));
            portInstance.ChannelFactory.Endpoint.Behaviors.Add(credentials);
        
            return portInstance as TPlugin;
        }
    }
    
    //  StructureMap injection
    For<PortType>()
        .Use((new PasswordDigestChannelFactory<PortTypeClient, PortType>("endPoint")).GetClient());
  • 相关阅读:
    ZJOI2019爆蛋记
    NOIp2018退役记
    拓展中国剩余定理(exCRT)摘要
    FFT(快速傅里叶变换)摘要
    主席树摘要
    LCT摘要
    替罪羊树摘要
    FHQ Treap摘要
    逻辑回归1-逻辑回归原理详解
    NLP自然语言处理原理及名词介绍
  • 原文地址:https://www.cnblogs.com/zeroone/p/4837113.html
Copyright © 2011-2022 走看看