/// <summary>
        /// RPC bind over TCP/IP, using specified endpoint and authenticate provider.
        /// </summary>
        /// <param name="serverName">NRPC server machine name.</param>
        /// <param name="endpoint">RPC endpoints, it's the port on TCP/IP.</param>
        /// <param name="securityContext">
        /// Security provider for RPC.
        /// Set the value to null to disable authentication.
        /// </param>
        /// <param name="timeout">Timeout for bind and all future requests.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when serverName is null.
        /// </exception>
        public void BindOverTcp(
            string serverName,
            ushort endpoint,
            ClientSecurityContext securityContext,
            TimeSpan timeout)
        {
            if (serverName == null)
            {
                throw new ArgumentNullException("serverName");
            }

            this.nrpcSecurityContext = securityContext as NrpcCustomClientSecurityContext;
            if (this.nrpcSecurityContext != null)
            {
                this.context = new NrpcCustomClientContext(this.nrpcSecurityContext.Context);
            }

            RpceAuthenticationLevel level = securityContext == null
                    ? RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_NONE
                    : (this.context.SealSecureChannel
                        ? RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT_PRIVACY
                        : RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT_INTEGRITY);

            this.customRpc.Bind(
                RpceUtility.RPC_OVER_TCPIP_PROTOCOL_SEQUENCE,
                serverName,
                endpoint.ToString(CultureInfo.InvariantCulture),
                null,
                securityContext,
                level,
                timeout);

            this.context.PrimaryName = serverName;
            NrpcCustomRpcAdapter nrpcRpcAdapter = this.customRpc as NrpcCustomRpcAdapter;

            if (nrpcRpcAdapter != null)
            {
                this.context.RpceTransportContext = nrpcRpcAdapter.RpceClientTransport.Context;
            }
        }
        /// <summary>
        /// RPC bind over named pipe, using well-known endpoint "\PIPE\NETLOGON".
        /// </summary>
        /// <param name="serverName">NRPC server machine name.</param>
        /// <param name="transportCredential">
        /// If connect by SMB/SMB2, it's the security credential
        /// used by underlayer transport (SMB/SMB2).
        /// If connect by TCP, this parameter is ignored.
        /// </param>
        /// <param name="securityContext">
        /// Security provider for RPC.
        /// Set the value to null to disable authentication.
        /// </param>
        /// <param name="timeout">Timeout for bind and all future requests.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when serverName is null.
        /// </exception>
        public void BindOverNamedPipe(
            string serverName,
            AccountCredential transportCredential,
            ClientSecurityContext securityContext,
            TimeSpan timeout)
        {
            if (serverName == null)
            {
                throw new ArgumentNullException("serverName");
            }

            this.nrpcSecurityContext = securityContext as NrpcCustomClientSecurityContext;
            if (this.nrpcSecurityContext != null)
            {
                this.context = new NrpcCustomClientContext(this.nrpcSecurityContext.Context);
            }

            RpceAuthenticationLevel level = securityContext == null ? RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_NONE
                    : (this.context.SealSecureChannel
                        ? RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT_PRIVACY
                        : RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT_INTEGRITY);

            this.customRpc.Bind(
                RpceUtility.RPC_OVER_NAMED_PIPE_PROTOCOL_SEQUENCE,
                serverName,
                NrpcUtility.NETLOGON_RPC_OVER_NP_WELLKNOWN_ENDPOINT,
                transportCredential,
                securityContext,
                level,
                timeout);

            this.context.PrimaryName = serverName;
            NrpcCustomRpcAdapter nrpcRpcAdapter = this.customRpc as NrpcCustomRpcAdapter;

            if (nrpcRpcAdapter != null)
            {
                this.context.RpceTransportContext = nrpcRpcAdapter.RpceClientTransport.Context;
            }
        }
 /// <summary>
 /// Initializes a new instance of the NrpcCustomClient class.
 /// </summary>
 /// <param name="domainName">Domain name.</param>
 public NrpcCustomClient(string domainName)
 {
     this.context            = new NrpcCustomClientContext();
     this.customRpc          = new NrpcCustomRpcAdapter();
     this.context.DomainName = domainName;
 }