码迷,mamicode.com
首页 > 其他好文 > 详细

wcf 访问控制

时间:2015-09-25 08:28:39      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

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());

 

wcf 访问控制

标签:

原文地址:http://www.cnblogs.com/zeroone/p/4837113.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!