Rediger

Del via


NegotiateStream Class

Definition

Provides a stream that uses the Negotiate security protocol to authenticate the client, and optionally the server, in client-server communication.

public ref class NegotiateStream : System::Net::Security::AuthenticatedStream
public class NegotiateStream : System.Net.Security.AuthenticatedStream
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public class NegotiateStream : System.Net.Security.AuthenticatedStream
type NegotiateStream = class
    inherit AuthenticatedStream
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
type NegotiateStream = class
    inherit AuthenticatedStream
Public Class NegotiateStream
Inherits AuthenticatedStream
Inheritance
Inheritance
Attributes

Examples

The following example demonstrates the client side of a client-server connection that uses the NegotiateStream. The client authenticates and sends a message to the server asynchronously.

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Net::Security;
using namespace System::Net::Sockets;
using namespace System::Text;

// The following class displays the properties of an authenticatedStream.
public ref class AuthenticatedStreamReporter
{
public:
   static void DisplayProperties( AuthenticatedStream^ stream )
   {
      Console::WriteLine( L"IsAuthenticated: {0}", stream->IsAuthenticated );
      Console::WriteLine( L"IsMutuallyAuthenticated: {0}", stream->IsMutuallyAuthenticated );
      Console::WriteLine( L"IsEncrypted: {0}", stream->IsEncrypted );
      Console::WriteLine( L"IsSigned: {0}", stream->IsSigned );
      Console::WriteLine( L"IsServer: {0}", stream->IsServer );
   }

};


public ref class ASynchronousAuthenticatingTcpClient
{
private:
   static TcpClient^ client = nullptr;

public:
   void Main()
   {
      
      // Establish the remote endpoint for the socket.
      // For this example, use the local machine.
      IPHostEntry^ ipHostInfo = Dns::GetHostEntry( Dns::GetHostName() );
      IPAddress^ ipAddress = ipHostInfo->AddressList[ 0 ];
      
      // Client and server use port 11000. 
      IPEndPoint^ remoteEP = gcnew IPEndPoint( ipAddress,11000 );
      
      // Create a TCP/IP socket.
      client = gcnew TcpClient;
      
      // Connect the socket to the remote endpoint.
      client->Connect( remoteEP );
      Console::WriteLine( L"Client connected to {0}.", remoteEP );
      
      // Ensure the client does not close when there is 
      // still data to be sent to the server.
      client->LingerState = (gcnew LingerOption( true,0 ));
      
      // Request authentication.
      NetworkStream^ clientStream = client->GetStream();
      NegotiateStream^ authStream = gcnew NegotiateStream( clientStream,false );
      
      // Pass the NegotiateStream as the AsyncState object 
      // so that it is available to the callback delegate.
      IAsyncResult^ ar = authStream->BeginAuthenticateAsClient( gcnew AsyncCallback( EndAuthenticateCallback ), authStream );
      
      Console::WriteLine( L"Client waiting for authentication..." );
      
      // Wait until the result is available.
      ar->AsyncWaitHandle->WaitOne();
      
      // Display the properties of the authenticated stream.
      AuthenticatedStreamReporter::DisplayProperties( authStream );
      
      // Send a message to the server.
      // Encode the test data into a byte array.
      array<Byte>^message = Encoding::UTF8->GetBytes( L"Hello from the client." );
      ar = authStream->BeginWrite( message, 0, message->Length, gcnew AsyncCallback( EndWriteCallback ), authStream );
      
      ar->AsyncWaitHandle->WaitOne();
      Console::WriteLine( L"Sent {0} bytes.", message->Length );
      
      // Close the client connection.
      authStream->Close();
      Console::WriteLine( L"Client closed." );
   }


   // The following method is called when the authentication completes.
   static void EndAuthenticateCallback( IAsyncResult^ ar )
   {
      Console::WriteLine( L"Client ending authentication..." );
      NegotiateStream^ authStream = dynamic_cast<NegotiateStream^>(ar->AsyncState);
      
      // End the asynchronous operation.
      authStream->EndAuthenticateAsClient( ar );
      
      //         Console.WriteLine("AllowedImpersonation: {0}", authStream.AllowedImpersonation);
   }


   // The following method is called when the write operation completes.
   static void EndWriteCallback( IAsyncResult^ ar )
   {
      Console::WriteLine( L"Client ending write operation..." );
      NegotiateStream^ authStream = dynamic_cast<NegotiateStream^>(ar->AsyncState);
      
      // End the asynchronous operation.
      authStream->EndWrite( ar );
   }

};

void main()
{
   ASynchronousAuthenticatingTcpClient^ aatc = gcnew ASynchronousAuthenticatingTcpClient;
   aatc->Main();
}
using System;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Text;

namespace Examples.NegotiateStreamExample
{
    public class ASynchronousAuthenticatingTcpClient
    {
        static TcpClient client = null;

        public static void Main(String[] args)
        {
            // Establish the remote endpoint for the socket.
            // For this example, use the local machine.
            IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost");
            IPAddress ipAddress = ipHostInfo.AddressList[0];
            // Client and server use port 11000.
            IPEndPoint remoteEP = new IPEndPoint(ipAddress, 11000);
            // Create a TCP/IP socket.
            client = new TcpClient();
            // Connect the socket to the remote endpoint.
            client.Connect(remoteEP);
            Console.WriteLine("Client connected to {0}.", remoteEP.ToString());
            // Ensure the client does not close when there is
            // still data to be sent to the server.
            client.LingerState = new LingerOption(true, 0);
            // Request authentication.
            NetworkStream clientStream = client.GetStream();
            NegotiateStream authStream = new NegotiateStream(clientStream, false);
            // Pass the NegotiateStream as the AsyncState object
            // so that it is available to the callback delegate.
            Task authenticateTask = authStream
                .AuthenticateAsClientAsync()
                .ContinueWith(task =>
                {
                    Console.WriteLine("Client ending authentication...");
                    Console.WriteLine("ImpersonationLevel: {0}", authStream.ImpersonationLevel);
                });

            Console.WriteLine("Client waiting for authentication...");
            // Wait until the result is available.
            authenticateTask.Wait();
            // Display the properties of the authenticated stream.
            AuthenticatedStreamReporter.DisplayProperties(authStream);
            // Send a message to the server.
            // Encode the test data into a byte array.
            byte[] message = Encoding.UTF8.GetBytes("Hello from the client.");
            Task writeTask = authStream
                .WriteAsync(message, 0, message.Length)
                .ContinueWith(task =>
                {
                    Console.WriteLine("Client ending write operation...");
                });

            writeTask.Wait();
            Console.WriteLine("Sent {0} bytes.", message.Length);
            // Close the client connection.
            authStream.Close();
            Console.WriteLine("Client closed.");
        }
    }

    // The following class displays the properties of an authenticatedStream.
    public class AuthenticatedStreamReporter
    {
        public static void DisplayProperties(AuthenticatedStream stream)
        {
            Console.WriteLine("IsAuthenticated: {0}", stream.IsAuthenticated);
            Console.WriteLine("IsMutuallyAuthenticated: {0}", stream.IsMutuallyAuthenticated);
            Console.WriteLine("IsEncrypted: {0}", stream.IsEncrypted);
            Console.WriteLine("IsSigned: {0}", stream.IsSigned);
            Console.WriteLine("IsServer: {0}", stream.IsServer);
        }
    }
}
Imports System.Text
Imports System.Net.Sockets
Imports System.Net.Security
Imports System.Net

Namespace Examples.NegotiateStreamExample

    Public Class ASynchronousAuthenticatingTcpClient

        Shared client As TcpClient = Nothing

        Public Shared Sub Main(args As String())
            ' Establish the remote endpoint for the socket.
            ' For this example, use the local machine.
            Dim ipHostInfo = Dns.GetHostEntry("localhost")
            Dim ipAddress = ipHostInfo.AddressList(0)

            ' Client and server use port 11000. 
            Dim remoteEP As New IPEndPoint(ipAddress, 11000)

            ' Create a TCP/IP socket.
            client = New TcpClient()

            ' Connect the socket to the remote endpoint.
            client.Connect(remoteEP)
            Console.WriteLine("Client connected to {0}.", remoteEP.ToString())

            ' Ensure the client does not close when there is 
            ' still data to be sent to the server.
            client.LingerState = (New LingerOption(True, 0))

            ' Request authentication.
            Dim clientStream = client.GetStream()
            Dim authStream As New NegotiateStream(clientStream, False)

            ' Pass the NegotiateStream as the AsyncState object 
            ' so that it is available to the callback delegate.
            Dim ar = authStream.BeginAuthenticateAsClient(
                New AsyncCallback(AddressOf EndAuthenticateCallback), authStream)

            Console.WriteLine("Client waiting for authentication...")

            ' Wait until the result is available.
            ar.AsyncWaitHandle.WaitOne()

            ' Display the properties of the authenticated stream.
            AuthenticatedStreamReporter.DisplayProperties(authStream)

            ' Send a message to the server.
            ' Encode the test data into a byte array.
            Dim message = Encoding.UTF8.GetBytes("Hello from the client.")
            ar = authStream.BeginWrite(message, 0, message.Length, 
                New AsyncCallback(AddressOf EndWriteCallback), authStream)
            ar.AsyncWaitHandle.WaitOne()
            Console.WriteLine("Sent {0} bytes.", message.Length)

            ' Close the client connection.
            authStream.Close()
            Console.WriteLine("Client closed.")

        End Sub

        ' The following method is called when the authentication completes.
        Public Shared Sub EndAuthenticateCallback(ar As IAsyncResult)

            Console.WriteLine("Client ending authentication...")
            Dim authStream = CType(ar.AsyncState, NegotiateStream)
            Console.WriteLine("ImpersonationLevel: {0}", authStream.ImpersonationLevel)

            ' End the asynchronous operation.
            authStream.EndAuthenticateAsClient(ar)

        End Sub

        ' The following method is called when the write operation completes.
        Public Shared Sub EndWriteCallback(ar As IAsyncResult)

            Console.WriteLine("Client ending write operation...")
            Dim authStream = CType(ar.AsyncState, NegotiateStream)

            ' End the asynchronous operation.
            authStream.EndWrite(ar)

        End Sub
    End Class

    ' The following class displays the properties of an AuthenticatedStream.
    Public Class AuthenticatedStreamReporter
        Public Shared Sub DisplayProperties(stream As AuthenticatedStream)
            Console.WriteLine("IsAuthenticated: {0}", stream.IsAuthenticated)
            Console.WriteLine("IsMutuallyAuthenticated: {0}", stream.IsMutuallyAuthenticated)
            Console.WriteLine("IsEncrypted: {0}", stream.IsEncrypted)
            Console.WriteLine("IsSigned: {0}", stream.IsSigned)
            Console.WriteLine("IsServer: {0}", stream.IsServer)
        End Sub
    End Class
End Namespace

The following code example demonstrates the server side of a client-server connection that uses the NegotiateStream to authenticate the client and read a message sent by the client.

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Net::Security;
using namespace System::Net::Sockets;
using namespace System::Security::Authentication;
using namespace System::Security::Principal;
using namespace System::Text;
using namespace System::IO;
using namespace System::Threading;

// ClientState is the AsyncState object.
private ref class ClientState
{
private:
   AuthenticatedStream^ authStream;
   TcpClient^ client;
   array<Byte>^buffer;
   StringBuilder^ message;
   ManualResetEvent^ waiter;

internal:
   ClientState( AuthenticatedStream^ a, TcpClient^ theClient )
   {
      authStream = a;
      client = theClient;
      message = nullptr;
      buffer = gcnew array<Byte>(2048);
      waiter = gcnew ManualResetEvent( false );
   }

internal:
   property TcpClient^ Client 
   {
      TcpClient^ get()
      {
         return client;
      }
   }

   property AuthenticatedStream^ AuthStream 
   {
      AuthenticatedStream^ get()
      {
         return authStream;
      }
  }

   property array<Byte>^ Buffer 
   {
      array<Byte>^ get()
      {
         return buffer;
      }

   }

   property StringBuilder^ Message 
   {
      StringBuilder^ get()
      {
         if ( message == nullptr )
                  message = gcnew StringBuilder;

         return message;
      }

   }

   property ManualResetEvent^ Waiter 
   {
      ManualResetEvent^ get()
      {
         return waiter;
      }

   }

};

public ref class AsynchronousAuthenticatingTcpListener
{
public:
   int Main()
   {
      
      // Create an IPv4 TCP/IP socket. 
      TcpListener^ listener = gcnew TcpListener( IPAddress::Any,11000 );
      
      // Listen for incoming connections.
      listener->Start();
      while ( true )
      {
         TcpClient^ clientRequest = nullptr;
         
         // Application blocks while waiting for an incoming connection.
         // Type CNTL-C to terminate the server.
         clientRequest = listener->AcceptTcpClient();
         Console::WriteLine( L"Client connected." );
         
         // A client has connected. 
         try
         {
            AuthenticateClient( clientRequest );
         }
         catch ( Exception^ e ) 
         {
            Console::WriteLine( e );
            continue;
         }

      }
   }


   static void AuthenticateClient( TcpClient^ clientRequest )
   {
      NetworkStream^ stream = clientRequest->GetStream();
      
      // Create the NegotiateStream.
      NegotiateStream^ authStream = gcnew NegotiateStream( stream,false );
      
      // Save the current client and NegotiateStream instance 
      // in a ClientState object.
      ClientState^ cState = gcnew ClientState( authStream,clientRequest );
      
      // Listen for the client authentication request.
      authStream->BeginAuthenticateAsServer( gcnew AsyncCallback( EndAuthenticateCallback ), cState );
      
      // Wait until the authentication completes.
      cState->Waiter->WaitOne();
      cState->Waiter->Reset();
      authStream->BeginRead( cState->Buffer, 0, cState->Buffer->Length, gcnew AsyncCallback( EndReadCallback ), cState );
      cState->Waiter->WaitOne();
      
      // Finished with the current client.
      authStream->Close();
      clientRequest->Close();
   }


   // The following method is invoked by the
   // BeginServerAuthenticate callback delegate.
   static void EndAuthenticateCallback( IAsyncResult^ ar )
   {
      
      // Get the saved data.
      ClientState^ cState = dynamic_cast<ClientState^>(ar->AsyncState);
      TcpClient^ clientRequest = cState->Client;
      NegotiateStream^ authStream = dynamic_cast<NegotiateStream^>(cState->AuthStream);
      Console::WriteLine( L"Ending authentication." );
      
      // Any exceptions that occurred during authentication are
      // thrown by the EndServerAuthenticate method.
      try
      {
         
         // This call blocks until the authentication is complete.
         authStream->EndAuthenticateAsServer( ar );
      }
      catch ( AuthenticationException^ e ) 
      {
         Console::WriteLine( e );
         Console::WriteLine( L"Authentication failed - closing connection." );
         cState->Waiter->Set();
         return;
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( e );
         Console::WriteLine( L"Closing connection." );
         cState->Waiter->Set();
         return;
      }

      
      // Display properties of the authenticated client.
      IIdentity^ id = authStream->RemoteIdentity;
      Console::WriteLine( L"{0} was authenticated using {1}.", id->Name, id->AuthenticationType );
      cState->Waiter->Set();
   }


   static void EndReadCallback( IAsyncResult^ ar )
   {
      
      // Get the saved data.
      ClientState^ cState = dynamic_cast<ClientState^>(ar->AsyncState);
      TcpClient^ clientRequest = cState->Client;
      NegotiateStream^ authStream = dynamic_cast<NegotiateStream^>(cState->AuthStream);
      
      // Get the buffer that stores the message sent by the client.
      int bytes = -1;
      
      // Read the client message.
      try
      {
         bytes = authStream->EndRead( ar );
         cState->Message->Append( Encoding::UTF8->GetChars( cState->Buffer, 0, bytes ) );
         if ( bytes != 0 )
         {
            authStream->BeginRead( cState->Buffer, 0, cState->Buffer->Length, gcnew AsyncCallback( EndReadCallback ), cState );
            return;
         }
      }
      catch ( Exception^ e ) 
      {
         
         // A real application should do something
         // useful here, such as logging the failure.
         Console::WriteLine( L"Client message exception:" );
         Console::WriteLine( e );
         cState->Waiter->Set();
         return;
      }

      IIdentity^ id = authStream->RemoteIdentity;
      Console::WriteLine( L"{0} says {1}", id->Name, cState->Message );
      cState->Waiter->Set();
   }

};

void main()
{
   AsynchronousAuthenticatingTcpListener^ aatl = gcnew AsynchronousAuthenticatingTcpListener;
   aatl->Main();
}

using System;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Principal;
using System.Text;
using System.IO;
using System.Threading;

namespace Examples.NegotiateStreamExample
{
    public class AsynchronousAuthenticatingTcpListener
    {
        public static void Main()
        {
            // Create an IPv4 TCP/IP socket.
            TcpListener listener = new TcpListener(IPAddress.Any, 11000);
            // Listen for incoming connections.
            listener.Start();
            while (true)
            {
                TcpClient clientRequest;
                // Application blocks while waiting for an incoming connection.
                // Type CNTL-C to terminate the server.
                clientRequest = listener.AcceptTcpClient();
                Console.WriteLine("Client connected.");
                // A client has connected.
                try
                {
                    AuthenticateClient(clientRequest);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }

        public static void AuthenticateClient(TcpClient clientRequest)
        {
            NetworkStream stream = clientRequest.GetStream();
            // Create the NegotiateStream.
            NegotiateStream authStream = new NegotiateStream(stream, false);
            // Save the current client and NegotiateStream instance
            // in a ClientState object.
            ClientState cState = new ClientState(authStream, clientRequest);
            // Listen for the client authentication request.
            Task authTask = authStream
                .AuthenticateAsServerAsync()
                .ContinueWith(task => { EndAuthenticateCallback(cState); });

            // Any exceptions that occurred during authentication are
            // thrown by the EndAuthenticateAsServer method.
            try
            {
                // This call blocks until the authentication is complete.
                authTask.Wait();
            }
            catch (AuthenticationException e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Authentication failed - closing connection.");
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Closing connection.");
                return;
            }

            Task<int> readTask = authStream
                .ReadAsync(cState.Buffer, 0, cState.Buffer.Length);

            readTask
                .ContinueWith((task) => { EndReadCallback(cState, task.Result); })
                .Wait();
            // Finished with the current client.
            authStream.Close();
            clientRequest.Close();
        }

        private static void EndAuthenticateCallback(ClientState cState)
        {
            // Get the saved data.
            NegotiateStream authStream = (NegotiateStream)cState.AuthenticatedStream;
            Console.WriteLine("Ending authentication.");

            // Display properties of the authenticated client.
            IIdentity id = authStream.RemoteIdentity;
            Console.WriteLine("{0} was authenticated using {1}.",
                id.Name,
                id.AuthenticationType
            );
        }

        private static void EndReadCallback(ClientState cState, int bytes)
        {
            NegotiateStream authStream = (NegotiateStream)cState.AuthenticatedStream;
            // Read the client message.
            try
            {
                cState.Message.Append(Encoding.UTF8.GetChars(cState.Buffer, 0, bytes));
                if (bytes != 0)
                {
                    Task<int> readTask = authStream.ReadAsync(cState.Buffer, 0, cState.Buffer.Length);
                    readTask
                        .ContinueWith(task => { EndReadCallback(cState, task.Result); })
                        .Wait();

                    return;
                }
            }
            catch (Exception e)
            {
                // A real application should do something
                // useful here, such as logging the failure.
                Console.WriteLine("Client message exception:");
                Console.WriteLine(e);
                return;
            }
            IIdentity id = authStream.RemoteIdentity;
            Console.WriteLine("{0} says {1}", id.Name, cState.Message.ToString());
        }
    }
    // ClientState is the AsyncState object.
    internal class ClientState
    {
        private StringBuilder _message = null;

        internal ClientState(AuthenticatedStream a, TcpClient theClient)
        {
            AuthenticatedStream = a;
            Client = theClient;
        }
        internal TcpClient Client { get; }

        internal AuthenticatedStream AuthenticatedStream { get; }

        internal byte[] Buffer { get; } = new byte[2048];

        internal StringBuilder Message
        {
            get { return _message ??= new StringBuilder(); }
        }
    }
}

Remarks

Use the NegotiateStream class for authentication and to help secure information transmitted between a client and a server. Using NegotiateStream, you can do the following.

  • Send the client's credentials to the server for Impersonation or Delegation.

  • Request server authentication.

  • Encrypt and/or sign data before transmitting it.

Authentication must be performed before transmitting information. Clients request authentication using the synchronous AuthenticateAsClient methods, which block until the authentication completes, or the asynchronous BeginAuthenticateAsClient methods, which do not block while waiting for the authentication to complete. Servers request authentication using the synchronous AuthenticateAsServer or asynchronous BeginAuthenticateAsServer methods. The client, and optionally the server, is authenticated using the Negotiate security protocol. The Kerberos protocol is used for authentication if both client and server support it; otherwise NTLM is used. The NegotiateStream class performs the authentication using the Security Support Provider Interface (SSPI).

When authentication succeeds, you must check the IsEncrypted and IsSigned properties to determine what security services will be used by the NegotiateStream to help secure your data during transmission. Check the IsMutuallyAuthenticated property to determine whether mutual authentication occurred. You can get information about the remote client or server using the RemoteIdentity property.

If the authentication fails, you will receive an AuthenticationException or a InvalidCredentialException. In this case, you can retry the authentication with a different credential.

You send data using the synchronous Write or asynchronous BeginWrite or WriteAsync methods. You receive data using the synchronous Read or asynchronous ReadAsync or BeginRead methods. If security services such as encryption or signing are enabled, these are automatically applied to your data by the NegotiateStream.

The NegotiateStream transmits data using a stream that you supply when creating the NegotiateStream. When you supply this underlying stream, you have the option to specify whether closing the NegotiateStream also closes the underlying stream.

Constructors

NegotiateStream(Stream, Boolean)

Initializes a new instance of the NegotiateStream class using the specified Stream and stream closure behavior.

NegotiateStream(Stream)

Initializes a new instance of the NegotiateStream class using the specified Stream.

Properties

CanRead

Gets a Boolean value that indicates whether the underlying stream is readable.

CanSeek

Gets a Boolean value that indicates whether the underlying stream is seekable.

CanTimeout

Gets a Boolean value that indicates whether the underlying stream supports time-outs.

CanWrite

Gets a Boolean value that indicates whether the underlying stream is writable.

ImpersonationLevel

Gets a value that indicates how the server can use the client's credentials.

InnerStream

Gets the stream used by this AuthenticatedStream for sending and receiving data.

(Inherited from AuthenticatedStream)
IsAuthenticated

Gets a Boolean value that indicates whether authentication was successful.

IsEncrypted

Gets a Boolean value that indicates whether this NegotiateStream uses data encryption.

IsMutuallyAuthenticated

Gets a Boolean value that indicates whether both the server and the client have been authenticated.

IsServer

Gets a Boolean value that indicates whether the local side of the connection used by this NegotiateStream was authenticated as the server.

IsSigned

Gets a Boolean value that indicates whether the data sent using this stream is signed.

LeaveInnerStreamOpen

Gets whether the stream used by this AuthenticatedStream for sending and receiving data has been left open.

(Inherited from AuthenticatedStream)
Length

Gets the length of the underlying stream.

Position

Gets or sets the current position in the underlying stream.

ReadTimeout

Gets or sets the amount of time a read operation blocks waiting for data.

RemoteIdentity

Gets information about the identity of the remote party sharing this authenticated stream.

WriteTimeout

Gets or sets the amount of time a write operation blocks waiting for data.

Methods

AuthenticateAsClient()

Called by clients to authenticate the client, and optionally the server, in a client-server connection.

AuthenticateAsClient(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel)

Called by clients to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified credential, authentication options, and channel binding.

AuthenticateAsClient(NetworkCredential, ChannelBinding, String)

Called by clients to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified client credential and the channel binding.

AuthenticateAsClient(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel)

Called by clients to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified credentials and authentication options.

AuthenticateAsClient(NetworkCredential, String)

Called by clients to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified client credential.

AuthenticateAsClientAsync()

Called by clients to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation.

AuthenticateAsClientAsync(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel)

Called by clients to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. The authentication process uses the specified credential, authentication options, and channel binding.

AuthenticateAsClientAsync(NetworkCredential, ChannelBinding, String)

Called by clients to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. The authentication process uses the specified client credential and the channel binding.

AuthenticateAsClientAsync(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel)

Called by clients to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. The authentication process uses the specified credentials and authentication options.

AuthenticateAsClientAsync(NetworkCredential, String)

Called by clients to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. The authentication process uses the specified client credential.

AuthenticateAsServer()

Called by servers to authenticate the client, and optionally the server, in a client-server connection.

AuthenticateAsServer(ExtendedProtectionPolicy)

Called by servers to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified extended protection policy.

AuthenticateAsServer(NetworkCredential, ExtendedProtectionPolicy, ProtectionLevel, TokenImpersonationLevel)

Called by servers to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified server credentials, authentication options, and extended protection policy.

AuthenticateAsServer(NetworkCredential, ProtectionLevel, TokenImpersonationLevel)

Called by servers to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified server credentials and authentication options.

AuthenticateAsServerAsync()

Called by servers to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation.

AuthenticateAsServerAsync(ExtendedProtectionPolicy)

Called by servers to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. The authentication process uses the specified extended protection policy.

AuthenticateAsServerAsync(NetworkCredential, ExtendedProtectionPolicy, ProtectionLevel, TokenImpersonationLevel)

Called by servers to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. The authentication process uses the specified server credentials, authentication options, and extended protection policy.

AuthenticateAsServerAsync(NetworkCredential, ProtectionLevel, TokenImpersonationLevel)

Called by servers to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. The authentication process uses the specified server credentials and authentication options.

BeginAuthenticateAsClient(AsyncCallback, Object)

Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. This method does not block.

BeginAuthenticateAsClient(NetworkCredential, ChannelBinding, String, AsyncCallback, Object)

Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified credentials and channel binding. This method does not block.

BeginAuthenticateAsClient(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified credentials, authentication options, and channel binding. This method does not block.

BeginAuthenticateAsClient(NetworkCredential, String, AsyncCallback, Object)

Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified credentials. This method does not block.

BeginAuthenticateAsClient(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified credentials and authentication options. This method does not block.

BeginAuthenticateAsServer(AsyncCallback, Object)

Called by servers to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. This method does not block.

BeginAuthenticateAsServer(ExtendedProtectionPolicy, AsyncCallback, Object)

Called by servers to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified extended protection policy. This method does not block.

BeginAuthenticateAsServer(NetworkCredential, ExtendedProtectionPolicy, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

Called by servers to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified server credentials, authentication options, and extended protection policy. This method does not block.

BeginAuthenticateAsServer(NetworkCredential, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

Called by servers to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. The authentication process uses the specified server credentials and authentication options. This method does not block.

BeginRead(Byte[], Int32, Int32, AsyncCallback, Object)

Begins an asynchronous read operation that reads data from the stream and stores it in the specified array.

BeginRead(Byte[], Int32, Int32, AsyncCallback, Object)

Begins an asynchronous read operation. (Consider using ReadAsync(Byte[], Int32, Int32) instead.)

(Inherited from Stream)
BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object)

Begins an asynchronous write operation that writes Bytes from the specified buffer to the stream.

BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object)

Begins an asynchronous write operation. (Consider using WriteAsync(Byte[], Int32, Int32) instead.)

(Inherited from Stream)
Close()

Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. Instead of calling this method, ensure that the stream is properly disposed.

(Inherited from Stream)
CopyTo(Stream, Int32)

Reads the bytes from the current stream and writes them to another stream, using a specified buffer size. Both streams positions are advanced by the number of bytes copied.

(Inherited from Stream)
CopyTo(Stream)

Reads the bytes from the current stream and writes them to another stream. Both streams positions are advanced by the number of bytes copied.

(Inherited from Stream)
CopyToAsync(Stream, CancellationToken)

Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified cancellation token. Both streams positions are advanced by the number of bytes copied.

(Inherited from Stream)
CopyToAsync(Stream, Int32, CancellationToken)

Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token. Both streams positions are advanced by the number of bytes copied.

(Inherited from Stream)
CopyToAsync(Stream, Int32)

Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size. Both streams positions are advanced by the number of bytes copied.

(Inherited from Stream)
CopyToAsync(Stream)

Asynchronously reads the bytes from the current stream and writes them to another stream. Both streams positions are advanced by the number of bytes copied.

(Inherited from Stream)
CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
CreateWaitHandle()
Obsolete.
Obsolete.
Obsolete.

Allocates a WaitHandle object.

(Inherited from Stream)
Dispose()

Releases all resources used by the Stream.

(Inherited from Stream)
Dispose(Boolean)

Releases the unmanaged resources used by the NegotiateStream and optionally releases the managed resources.

Dispose(Boolean)

Releases the unmanaged resources used by the AuthenticatedStream and optionally releases the managed resources.

(Inherited from AuthenticatedStream)
DisposeAsync()

Asynchronously releases the unmanaged and managed resources used by the NegotiateStream.

DisposeAsync()

Asynchronously releases the unmanaged and managed resources used by the AuthenticatedStream.

(Inherited from AuthenticatedStream)
EndAuthenticateAsClient(IAsyncResult)

Ends a pending asynchronous client authentication operation that was started with a call to BeginAuthenticateAsClient.

EndAuthenticateAsServer(IAsyncResult)

Ends a pending asynchronous client authentication operation that was started with a call to BeginAuthenticateAsServer.

EndRead(IAsyncResult)

Ends an asynchronous read operation that was started with a call to BeginRead(Byte[], Int32, Int32, AsyncCallback, Object).

EndRead(IAsyncResult)

Waits for the pending asynchronous read to complete. (Consider using ReadAsync(Byte[], Int32, Int32) instead.)

(Inherited from Stream)
EndWrite(IAsyncResult)

Ends an asynchronous write operation that was started with a call to BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object).

EndWrite(IAsyncResult)

Ends an asynchronous write operation. (Consider using WriteAsync(Byte[], Int32, Int32) instead.)

(Inherited from Stream)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Flush()

Causes any buffered data to be written to the underlying device.

FlushAsync()

Asynchronously clears all buffers for this stream and causes any buffered data to be written to the underlying device.

(Inherited from Stream)
FlushAsync(CancellationToken)

Asynchronously writes any buffered data to the underlying device.

FlushAsync(CancellationToken)

Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.

(Inherited from Stream)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ObjectInvariant()
Obsolete.

Provides support for a Contract.

(Inherited from Stream)
Read(Byte[], Int32, Int32)

Reads data from this stream and stores it in the specified array.

Read(Span<Byte>)

When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

(Inherited from Stream)
ReadAsync(Byte[], Int32, Int32, CancellationToken)

Reads data asynchronously from this stream and stores it in the specified array.

ReadAsync(Byte[], Int32, Int32, CancellationToken)

Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

(Inherited from Stream)
ReadAsync(Byte[], Int32, Int32)

Asynchronously reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

(Inherited from Stream)
ReadAsync(Memory<Byte>, CancellationToken)

Reads data asynchronously from the NegotiateStream and stores it in a byte memory range as an asynchronous operation.

ReadAsync(Memory<Byte>, CancellationToken)

Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

(Inherited from Stream)
ReadAtLeast(Span<Byte>, Int32, Boolean)

Reads at least a minimum number of bytes from the current stream and advances the position within the stream by the number of bytes read.

(Inherited from Stream)
ReadAtLeastAsync(Memory<Byte>, Int32, Boolean, CancellationToken)

Asynchronously reads at least a minimum number of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

(Inherited from Stream)
ReadByte()

Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.

(Inherited from Stream)
ReadExactly(Byte[], Int32, Int32)

Reads count number of bytes from the current stream and advances the position within the stream.

(Inherited from Stream)
ReadExactly(Span<Byte>)

Reads bytes from the current stream and advances the position within the stream until the buffer is filled.

(Inherited from Stream)
ReadExactlyAsync(Byte[], Int32, Int32, CancellationToken)

Asynchronously reads count number of bytes from the current stream, advances the position within the stream, and monitors cancellation requests.

(Inherited from Stream)
ReadExactlyAsync(Memory<Byte>, CancellationToken)

Asynchronously reads bytes from the current stream, advances the position within the stream until the buffer is filled, and monitors cancellation requests.

(Inherited from Stream)
Seek(Int64, SeekOrigin)

Throws NotSupportedException.

SetLength(Int64)

Sets the length of the underlying stream.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
Write(Byte[], Int32, Int32)

Write the specified number of Bytes to the underlying stream using the specified buffer and offset.

Write(ReadOnlySpan<Byte>)

When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

(Inherited from Stream)
WriteAsync(Byte[], Int32, Int32, CancellationToken)

Write asynchronously the specified number of Bytes to the underlying stream.

WriteAsync(Byte[], Int32, Int32, CancellationToken)

Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

(Inherited from Stream)
WriteAsync(Byte[], Int32, Int32)

Asynchronously writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

(Inherited from Stream)
WriteAsync(ReadOnlyMemory<Byte>, CancellationToken)

Write asynchronously the specified number of Bytes to the underlying stream.

WriteAsync(ReadOnlyMemory<Byte>, CancellationToken)

Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

(Inherited from Stream)
WriteByte(Byte)

Writes a byte to the current position in the stream and advances the position within the stream by one byte.

(Inherited from Stream)

Extension Methods

CopyToAsync(Stream, PipeWriter, CancellationToken)

Asynchronously reads the bytes from the Stream and writes them to the specified PipeWriter, using a cancellation token.

ConfigureAwait(IAsyncDisposable, Boolean)

Configures how awaits on the tasks returned from an async disposable will be performed.

Applies to

See also