首页 > 其他 > 详细

wcf 访问控制

时间:2015-09-25 08:27:24      阅读:114      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!