/// <summary>
        /// Dispose method.
        /// </summary>
        /// <param name="disposing">
        /// True to release both managed and unmanaged resources.<para/>
        /// False to release unmanaged resources only.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Release managed resources.
                if (nrpc != null)
                {
                    nrpc.Dispose();
                    nrpc = null;
                }
            }

            // Release unmanaged resources.
        }
        /// <summary>
        /// Initialize an instance of NrpcClientSecurityContext class. 
        /// By calling this constructor, the class will setup a new secure 
        /// channel between client and server.
        /// </summary>
        /// <param name="domainName">
        /// The NRPC domain name.
        /// </param>
        /// <param name="serverName">
        /// The NRPC server name.
        /// </param>
        /// <param name="credential">
        /// The credential to setup the secure channel.
        /// </param>
        /// <param name="requestConfidentiality">
        /// A Boolean setting that indicates that the caller is requiring 
        /// encryption of messages so that they cannot be read while in transit. 
        /// Requesting this service results in Netlogon encrypting the message.
        /// </param>
        /// <param name="clientCapabilities">
        /// The client capability.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when domainName, serverName or credential is null.
        /// </exception>
        public NrpcClientSecurityContext(
            string domainName,
            string serverName,
            MachineAccountCredential credential,
            bool requestConfidentiality,
            NrpcNegotiateFlags clientCapabilities)
        {
            if (string.IsNullOrWhiteSpace(domainName))
            {
                throw new ArgumentNullException("domainName cannot be null or empty");
            }
            if (string.IsNullOrWhiteSpace(serverName))
            {
                throw new ArgumentNullException("serverName cannot be null or empty");
            }
            if (credential == null)
            {
                throw new ArgumentNullException("credential cannot be null");
            }

            this.nrpc = NrpcClient.CreateNrpcClient(domainName);
            this.nrpc.Context.PrimaryName = serverName;
            this.nrpc.Context.SealSecureChannel = requestConfidentiality;
            this.nrpc.Context.NegotiateFlags = clientCapabilities;

            this.credential = credential;
            this.secureChannelType = _NETLOGON_SECURE_CHANNEL_TYPE.WorkstationSecureChannel;
        }
 /// <summary>
 /// used to request a managed Nrpc client
 /// </summary>
 /// <param name="name">domain name</param>
 /// <returns>Nrpc client instance</returns>
 public static NrpcClient CreateNrpcClient(string dn)
 {
     NrpcClient c = new NrpcClient(dn);
     m_nrpcClients.Add(c);
     return c;
 }