protected virtual void Dispose(bool disposing) { if (!disposing) { return; } if (this.drsConnection != null) { this.drsConnection.Dispose(); this.drsConnection = null; } if (this.rpcConnection != null) { this.rpcConnection.Dispose(); this.rpcConnection = null; } if(this.npConnection != null) { this.npConnection.Dispose(); this.npConnection = null; } }
private void CreateRpcConnection(string server, RpcProtocol protocol, NetworkCredential credential = null) { EndpointBindingInfo binding; switch(protocol) { case RpcProtocol.TCP: binding = new EndpointBindingInfo(RpcProtseq.ncacn_ip_tcp, server, null); break; case RpcProtocol.SMB: binding = new EndpointBindingInfo(RpcProtseq.ncacn_np, server, DrsNamedPipeName); if(credential != null) { // Connect named pipe this.npConnection = new NamedPipeConnection(server, credential); } break; default: // TODO: Custom exception type // TODO: Extract as string throw new Exception("Unsupported RPC protocol"); } NetworkCredential rpcCredential = credential ?? Client.Self; this.rpcConnection = new NativeClient(binding); this.rpcConnection.AuthenticateAs(rpcCredential); }