Exemplo n.º 1
0
        public static void SetCredentials <T, C>(this DuplexChannelFactory <T, C> factory, string domain, string userName, string password, TokenImpersonationLevel impersonationLevel) where T : class
        {
            if (factory.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            ServiceEndpoint[] endpoints = { factory.Endpoint };

            SecurityBehavior.ConfigureIntranet(endpoints);

            NetworkCredential credentials = new NetworkCredential();

            credentials.Domain   = domain;
            credentials.UserName = userName;
            credentials.Password = password;

            factory.Credentials.Windows.ClientCredential          = credentials;
            factory.Credentials.Windows.AllowedImpersonationLevel = impersonationLevel;
        }
Exemplo n.º 2
0
      /// <summary>
      /// Can only call before using the proxy for the first time
      /// </summary>
      public static void SecureProxy<T>(ClientBase<T> proxy,string domain,string userName,string password,TokenImpersonationLevel impersonationLevel) where T : class
      {
         if(proxy.State == CommunicationState.Opened)
         {
            throw new InvalidOperationException("Proxy channel is already opened");
         }
         Collection<ServiceEndpoint> endpoints = new Collection<ServiceEndpoint>();
         endpoints.Add(proxy.Endpoint);

         SecurityBehavior.ConfigureIntranet(endpoints);

         NetworkCredential credentials = new NetworkCredential();
         credentials.Domain   = domain;
         credentials.UserName = userName;
         credentials.Password = password;

         proxy.ClientCredentials.Windows.ClientCredential = credentials;
         proxy.ClientCredentials.Windows.AllowedImpersonationLevel = impersonationLevel;
      }