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());
  • 相关阅读:
    三种省市级联下拉列表的写法
    三种省市级联下拉列表的写法
    SQL经典试题(mysql)
    60行代码俄罗斯方块
    ibatis xml中配置信息详解
    60行代码俄罗斯方块
    xinetd
    csh and tcsh
    xinetd restart
    bash sh
  • 原文地址:https://www.cnblogs.com/zeroone/p/4837113.html
Copyright © 2011-2022 走看看