/// <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"); } nrpcSecurityContext = securityContext as NrpcClientSecurityContext; if (nrpcSecurityContext != null) { context = nrpcSecurityContext.nrpc.context; } rpc.Bind( RpceUtility.RPC_OVER_TCPIP_PROTOCOL_SEQUENCE, serverName, endpoint.ToString(CultureInfo.InvariantCulture), null, securityContext, securityContext == null ? RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_NONE : (context.SealSecureChannel ? RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT_PRIVACY : RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT_INTEGRITY), timeout); context.PrimaryName = serverName; NrpcRpcAdapter nrpcRpcAdapter = rpc as NrpcRpcAdapter; if (nrpcRpcAdapter != null) { context.rpceTransportContext = nrpcRpcAdapter.rpceClientTransport.Context; } }
/// <summary> /// Constructor, initialize a NRPC client.<para/> /// Create the instance will not connect to server, /// you should call one of BindOverTcp or BindOverNamedPipe /// to actually connect to NRPC server. /// </summary> /// <param name="domainName">Domain name</param> private NrpcClient(string domainName) { context = new NrpcClientContext(); context.DomainName = domainName; rpc = new NrpcRpcAdapter(); }
/// <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 under layer 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"); } nrpcSecurityContext = securityContext as NrpcClientSecurityContext; if (nrpcSecurityContext != null) { context = nrpcSecurityContext.nrpc.context; } rpc.Bind( RpceUtility.RPC_OVER_NAMED_PIPE_PROTOCOL_SEQUENCE, serverName, NrpcUtility.NETLOGON_RPC_OVER_NP_WELLKNOWN_ENDPOINT, transportCredential, securityContext, securityContext == null ? RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_NONE : (context.SealSecureChannel ? RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT_PRIVACY : RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT_INTEGRITY), timeout); context.PrimaryName = serverName; NrpcRpcAdapter nrpcRpcAdapter = rpc as NrpcRpcAdapter; if (nrpcRpcAdapter != null) { context.rpceTransportContext = nrpcRpcAdapter.rpceClientTransport.Context; } }