예제 #1
0
        /// <summary>
        /// Connect the client to a RPC endpoint.
        /// </summary>
        /// <param name="endpoint">The endpoint for RPC server.</param>
        /// <param name="transport_security">The transport security for the connection.</param>
        public void Connect(RpcEndpoint endpoint, RpcTransportSecurity transport_security)
        {
            if (Connected)
            {
                throw new InvalidOperationException("RPC client is already connected.");
            }

            if (endpoint == null)
            {
                throw new ArgumentNullException("Must specify an endpoint", nameof(endpoint));
            }

            try
            {
                _transport = RpcClientTransportFactory.ConnectEndpoint(endpoint, transport_security);
                _transport.Bind(InterfaceId, InterfaceVersion, NdrNativeUtils.DCE_TransferSyntax, new Version(2, 0));
                ObjectUuid = endpoint.ObjectUuid;
            }
            catch
            {
                // Disconnect transport on any exception.
                _transport?.Disconnect();
                _transport = null;
                throw;
            }
        }
        public static byte[] ToArray(RpcTransportSecurity transport_security, int auth_padding_length, int context_id, byte[] security_data)
        {
            MemoryStream stm    = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stm);
            AuthData     data   = new AuthData(transport_security.AuthenticationType, transport_security.AuthenticationLevel,
                                               auth_padding_length, context_id, security_data);

            data.Write(writer, auth_padding_length);
            return(stm.ToArray());
        }
예제 #3
0
        /// <summary>
        /// Connect the client to a RPC endpoint.
        /// </summary>
        /// <param name="string_binding">The binding string for the RPC server.</param>
        /// <param name="transport_security">The transport security for the connection.</param>
        public void Connect(string string_binding, RpcTransportSecurity transport_security)
        {
            var endpoint = new RpcEndpoint(InterfaceId, InterfaceVersion, string_binding, false);

            if (string.IsNullOrEmpty(endpoint.ProtocolSequence))
            {
                throw new ArgumentException("Binding string must contain a protocol sequence.");
            }

            if (string.IsNullOrEmpty(endpoint.Endpoint))
            {
                endpoint = LookupEndpoint(string_binding);
            }

            Connect(endpoint, transport_security);
        }
예제 #4
0
 /// <summary>
 /// Connect the client to a RPC endpoint.
 /// </summary>
 /// <param name="protocol_seq">The protocol sequence for the transport.</param>
 /// <param name="endpoint">The endpoint for the protocol sequence.</param>
 /// <param name="transport_security">The transport security for the connection.</param>
 public void Connect(string protocol_seq, string endpoint, RpcTransportSecurity transport_security)
 {
     Connect(protocol_seq, endpoint, null, transport_security);
 }
예제 #5
0
        /// <summary>
        /// Connect the client to a RPC endpoint.
        /// </summary>
        /// <param name="protocol_seq">The protocol sequence for the transport.</param>
        /// <param name="endpoint">The endpoint for the protocol sequence.</param>
        /// <param name="network_address">The network address for the protocol sequence.</param>
        /// <param name="transport_security">The transport security for the connection.</param>
        public void Connect(string protocol_seq, string endpoint, string network_address, RpcTransportSecurity transport_security)
        {
            if (Connected)
            {
                throw new InvalidOperationException("RPC client is already connected.");
            }

            if (string.IsNullOrEmpty(protocol_seq))
            {
                throw new ArgumentException("Must specify a protocol sequence", nameof(protocol_seq));
            }

            Connect(string.IsNullOrEmpty(endpoint) ? LookupEndpoint(protocol_seq, network_address) :
                    new RpcEndpoint(InterfaceId, InterfaceVersion,
                                    SafeRpcBindingHandle.Compose(null, protocol_seq,
                                                                 string.IsNullOrEmpty(network_address) ? null : network_address, endpoint, null), true),
                    transport_security);
        }