예제 #1
0
        public Client(EndpointBindingInfo endpointBindingInfo)
        {
            _handle   = new RpcClientHandle();
            _protocol = endpointBindingInfo.Protseq;
            _binding  = stringBindingCompose(endpointBindingInfo, null);
            RpcTrace.Verbose("Client('{0}:{1}')", endpointBindingInfo.NetworkAddr, endpointBindingInfo.EndPoint);

            bindingFromStringBinding(_handle, _binding);
        }
예제 #2
0
        // Creates a string binding handle.
        // This function is nothing more than a printf.
        // Connection is not done here.
        private static String stringBindingCompose(EndpointBindingInfo endpointBindingInfo,
                                                   String Options)
        {
            IntPtr     lpBindingString;
            RPC_STATUS result = NativeMethods.RpcStringBindingCompose(null, endpointBindingInfo.Protseq.ToString(), endpointBindingInfo.NetworkAddr, endpointBindingInfo.EndPoint, Options,
                                                                      out lpBindingString);

            Guard.Assert(result);

            try
            {
                return(Marshal.PtrToStringUni(lpBindingString));
            }
            finally
            {
                Guard.Assert(NativeMethods.RpcStringFree(ref lpBindingString));
            }
        }
 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);
 }