NegotiateStream 类

定义

提供一个使用协商安全协议的流,以便对客户端-服务器通信中的客户端及服务器(可选)进行身份验证。

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
继承
继承
属性

示例

以下示例演示使用 NegotiateStream的客户端-服务器连接的客户端。 客户端对服务器进行身份验证,并异步向服务器发送消息。

#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

下面的代码示例演示客户端-服务器连接的服务器端,该连接使用 NegotiateStream 对客户端进行身份验证并读取客户端发送的消息。

#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(); }
        }
    }
}

注解

NegotiateStream使用 类进行身份验证,以帮助保护在客户端和服务器之间传输的信息。 使用 NegotiateStream,可以执行以下操作。

  • 将客户端凭据发送到服务器进行模拟或委派。

  • 请求服务器身份验证。

  • 在传输数据之前加密和/或签名数据。

在传输信息之前,必须执行身份验证。 客户端使用同步 AuthenticateAsClient 方法(在身份验证完成之前阻止)或异步 BeginAuthenticateAsClient 方法(在等待身份验证完成时不阻止)请求身份验证。 服务器使用同步 AuthenticateAsServer 或异步 BeginAuthenticateAsServer 方法请求身份验证。 客户端(可选)使用协商安全协议进行身份验证。 如果客户端和服务器都支持 Kerberos 协议,则将其用于身份验证;否则使用 NTLM。 类 NegotiateStream 使用安全支持提供程序接口 (SSPI) 进行身份验证。

身份验证成功后,必须检查 IsEncryptedIsSigned 属性,以确定 将使用 NegotiateStream 哪些安全服务来帮助在传输过程中保护数据。 IsMutuallyAuthenticated检查 属性以确定是否发生了相互身份验证。 可以使用 属性获取有关远程客户端或服务器 RemoteIdentity 的信息。

如果身份验证失败,将收到 AuthenticationExceptionInvalidCredentialException。 在这种情况下,可以使用其他凭据重试身份验证。

使用同步 Write 或异步 BeginWriteWriteAsync 方法发送数据。 使用同步 Read 或异步 ReadAsyncBeginRead 方法接收数据。 如果启用了加密或签名等安全服务,这些服务将自动由 NegotiateStream应用于数据。

使用 NegotiateStream 创建 NegotiateStream时提供的流传输数据。 提供此基础流时,可以选择指定关闭 NegotiateStream 是否同时关闭基础流。

构造函数

NegotiateStream(Stream)

使用指定的 NegotiateStream 初始化 Stream 类的新实例。

NegotiateStream(Stream, Boolean)

使用指定的 NegotiateStream 和流封闭行为初始化 Stream 类的新实例。

属性

CanRead

获取一个 Boolean 值,该值指示基础流是否可读。

CanSeek

获取一个 Boolean 值,该值指示基础流是否可查找。

CanTimeout

获取一个 Boolean 值,该值指示基础流是否支持超时。

CanWrite

获取一个 Boolean 值,该值指示基础流是否可写。

ImpersonationLevel

获取一个值,该值指示服务器使用客户端凭据的方法。

InnerStream

获取此 AuthenticatedStream 用来发送和接收数据的流。

(继承自 AuthenticatedStream)
IsAuthenticated

获取一个 Boolean 值,该值指示身份验证是否成功。

IsEncrypted

获取一个 Boolean 值,该值指示此 NegotiateStream 是否使用数据加密。

IsMutuallyAuthenticated

获取一个 Boolean 值,该值指示服务器和客户端是否均已进行身份验证。

IsServer

获取一个 Boolean 值,该值指示此 NegotiateStream 使用的连接的本地端是否作为服务器进行了身份验证。

IsSigned

获取一个 Boolean 值,该值指示使用此流发送的数据是否进行签名。

LeaveInnerStreamOpen

获取此 AuthenticatedStream 用来发送和接收数据的流是否保持打开。

(继承自 AuthenticatedStream)
Length

获取基础流的长度。

Position

获取或设置基础流中的当前位置。

ReadTimeout

获取或设置读操作阻止等待数据的时间。

RemoteIdentity

获取有关共享此已验证身份的流的远程方的身份信息。

WriteTimeout

获取或设置写操作阻止等待数据的时间。

方法

AuthenticateAsClient()

客户端调用此方法,以便对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。

AuthenticateAsClient(NetworkCredential, ChannelBinding, String)

客户端调用此方法,以便对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的客户端凭据和通道绑定。

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

客户端调用此方法,以便对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据、身份验证选项和通道绑定。

AuthenticateAsClient(NetworkCredential, String)

客户端调用此方法,以便对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的客户端凭据。

AuthenticateAsClient(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel)

客户端调用此方法,以便对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据和身份验证选项。

AuthenticateAsClientAsync()

客户端调用此方法,对客户端/服务器连接中的客户端及服务器(可选)进行身份验证以作为异步操作。

AuthenticateAsClientAsync(NetworkCredential, ChannelBinding, String)

客户端调用此方法,对客户端/服务器连接中的客户端及服务器(可选)进行身份验证以作为异步操作。 身份验证过程使用指定的客户端凭据和通道绑定。

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

客户端调用此方法,对客户端/服务器连接中的客户端及服务器(可选)进行身份验证以作为异步操作。 身份验证过程使用指定的凭据、身份验证选项和通道绑定。

AuthenticateAsClientAsync(NetworkCredential, String)

客户端调用此方法,对客户端/服务器连接中的客户端及服务器(可选)进行身份验证以作为异步操作。 身份验证过程使用指定的客户端凭据。

AuthenticateAsClientAsync(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel)

客户端调用此方法,对客户端/服务器连接中的客户端及服务器(可选)进行身份验证以作为异步操作。 身份验证过程使用指定的凭据和身份验证选项。

AuthenticateAsServer()

服务器调用此方法,以便对客户端-服务器连接中的客户端及服务器(可选)进行身份验证。

AuthenticateAsServer(ExtendedProtectionPolicy)

服务器调用此方法,以便对客户端-服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的扩展保护策略。

AuthenticateAsServer(NetworkCredential, ExtendedProtectionPolicy, ProtectionLevel, TokenImpersonationLevel)

服务器调用此方法,以便对客户端-服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的服务器凭据、身份验证选项和扩展保护策略。

AuthenticateAsServer(NetworkCredential, ProtectionLevel, TokenImpersonationLevel)

服务器调用此方法,以便对客户端-服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的服务器凭据和身份验证选项。

AuthenticateAsServerAsync()

服务器调用此方法,对客户端-服务器连接中的客户端及服务器(可选)进行身份验证以作为异步操作。

AuthenticateAsServerAsync(ExtendedProtectionPolicy)

服务器调用此方法,对客户端-服务器连接中的客户端及服务器(可选)进行身份验证以作为异步操作。 身份验证过程使用指定的扩展保护策略。

AuthenticateAsServerAsync(NetworkCredential, ExtendedProtectionPolicy, ProtectionLevel, TokenImpersonationLevel)

服务器调用此方法,对客户端-服务器连接中的客户端及服务器(可选)进行身份验证以作为异步操作。 身份验证过程使用指定的服务器凭据、身份验证选项和扩展保护策略。

AuthenticateAsServerAsync(NetworkCredential, ProtectionLevel, TokenImpersonationLevel)

服务器调用此方法,对客户端-服务器连接中的客户端及服务器(可选)进行身份验证以作为异步操作。 身份验证过程使用指定的服务器凭据和身份验证选项。

BeginAuthenticateAsClient(AsyncCallback, Object)

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 此方法不会进入阻止状态。

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

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据和通道绑定。 此方法不会进入阻止状态。

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

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据、身份验证选项和通道绑定。 此方法不会进入阻止状态。

BeginAuthenticateAsClient(NetworkCredential, String, AsyncCallback, Object)

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据。 此方法不会进入阻止状态。

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

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据和身份验证选项。 此方法不会进入阻止状态。

BeginAuthenticateAsServer(AsyncCallback, Object)

服务器调用此方法开始一个异步操作,以对客户端-服务器连接中的客户端及服务器(可选)进行身份验证。 此方法不会进入阻止状态。

BeginAuthenticateAsServer(ExtendedProtectionPolicy, AsyncCallback, Object)

服务器调用此方法开始一个异步操作,以对客户端-服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的扩展保护策略。 此方法不会进入阻止状态。

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

服务器调用此方法开始一个异步操作,以对客户端-服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的服务器凭据、身份验证选项和扩展保护策略。 此方法不会进入阻止状态。

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

服务器调用此方法开始一个异步操作,以对客户端-服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的服务器凭据和身份验证选项。 此方法不会进入阻止状态。

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

开始一个异步读操作,此操作读取流中的数据并将其存储在指定的数组中。

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

开始异步读操作。 (请考虑改用 ReadAsync(Byte[], Int32, Int32)。)

(继承自 Stream)
BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object)

开始一个异步写操作,此操作将指定缓冲区中的 Byte 写入到流中。

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

开始异步写操作。 (请考虑改用 WriteAsync(Byte[], Int32, Int32)。)

(继承自 Stream)
Close()

关闭当前流并释放与之关联的所有资源(如套接字和文件句柄)。 不直接调用此方法,而应确保流得以正确释放。

(继承自 Stream)
CopyTo(Stream)

从当前流中读取字节并将其写入到另一流中。 这两个流位置都按复制的字节数提前。

(继承自 Stream)
CopyTo(Stream, Int32)

使用指定的缓冲区大小,从当前流中读取字节并将其写入到另一流中。 这两个流位置都按复制的字节数提前。

(继承自 Stream)
CopyToAsync(Stream)

从当前流中异步读取字节并将其写入到另一个流中。 这两个流位置都按复制的字节数提前。

(继承自 Stream)
CopyToAsync(Stream, CancellationToken)

通过指定的取消令牌,从当前流中异步读取字节并将其写入到另一个流中。 这两个流位置都按复制的字节数提前。

(继承自 Stream)
CopyToAsync(Stream, Int32)

使用指定的缓冲区大小,从当前流中异步读取字节并将其写入到另一流中。 这两个流位置都按复制的字节数提前。

(继承自 Stream)
CopyToAsync(Stream, Int32, CancellationToken)

使用指定的缓冲区大小和取消令牌,从当前流中异步读取字节并将其写入到另一个流中。 这两个流位置都按复制的字节数提前。

(继承自 Stream)
CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(继承自 MarshalByRefObject)
CreateWaitHandle()
已过时.
已过时.
已过时.

分配 WaitHandle 对象。

(继承自 Stream)
Dispose()

释放由 Stream 使用的所有资源。

(继承自 Stream)
Dispose(Boolean)

释放由 NegotiateStream 占用的非托管资源,还可以另外再释放托管资源。

Dispose(Boolean)

释放由 AuthenticatedStream 占用的非托管资源,还可以另外再释放托管资源。

(继承自 AuthenticatedStream)
DisposeAsync()

异步释放 NegotiateStream 使用的非托管资源和受管理资源。

DisposeAsync()

异步释放 AuthenticatedStream 使用的非托管资源和受管理资源。

(继承自 AuthenticatedStream)
EndAuthenticateAsClient(IAsyncResult)

结束通过调用 BeginAuthenticateAsClient 而启动的、正处于挂起状态的异步客户端身份验证操作。

EndAuthenticateAsServer(IAsyncResult)

结束通过调用 BeginAuthenticateAsServer 而启动的、正处于挂起状态的异步客户端身份验证操作。

EndRead(IAsyncResult)

结束通过调用 BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) 而启动的异步读操作。

EndRead(IAsyncResult)

等待挂起的异步读取完成。 (请考虑改用 ReadAsync(Byte[], Int32, Int32)。)

(继承自 Stream)
EndWrite(IAsyncResult)

结束通过调用 BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) 而启动的异步写操作。

EndWrite(IAsyncResult)

结束异步写操作。 (请考虑改用 WriteAsync(Byte[], Int32, Int32)。)

(继承自 Stream)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Flush()

导致所有缓冲数据都要写入基础设备。

FlushAsync()

异步清除此流的所有缓冲区并导致所有缓冲数据都写入基础设备中。

(继承自 Stream)
FlushAsync(CancellationToken)

将所有缓冲数据异步写入基础设备。

FlushAsync(CancellationToken)

异步清理此流的所有缓冲区,导致所有缓冲数据都写入基础设备,并且监控取消请求。

(继承自 Stream)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetLifetimeService()
已过时.

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetType()

获取当前实例的 Type

(继承自 Object)
InitializeLifetimeService()
已过时.

获取生存期服务对象来控制此实例的生存期策略。

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(继承自 MarshalByRefObject)
ObjectInvariant()
已过时.

提供对 Contract 的支持。

(继承自 Stream)
Read(Byte[], Int32, Int32)

读取此流中的数据并将其存储在指定的数组中。

Read(Span<Byte>)

当在派生类中重写时,从当前流读取字节序列,并将此流中的位置提升读取的字节数。

(继承自 Stream)
ReadAsync(Byte[], Int32, Int32)

从当前流异步读取字节序列,并将流中的位置提升读取的字节数。

(继承自 Stream)
ReadAsync(Byte[], Int32, Int32, CancellationToken)

异步读取此流中的数据并将其存储在指定的数组中。

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

从当前流异步读取字节的序列,将流中的位置提升读取的字节数,并监视取消请求。

(继承自 Stream)
ReadAsync(Memory<Byte>, CancellationToken)

以异步操作形式,从 NegotiateStream 读取数据,并将其存储在字节内存范围内。

ReadAsync(Memory<Byte>, CancellationToken)

从当前流异步读取字节的序列,将流中的位置提升读取的字节数,并监视取消请求。

(继承自 Stream)
ReadAtLeast(Span<Byte>, Int32, Boolean)

从当前流中读取至少最小字节数,并将流中的位置向前推进读取的字节数。

(继承自 Stream)
ReadAtLeastAsync(Memory<Byte>, Int32, Boolean, CancellationToken)

从当前流异步读取至少最小字节数,按读取的字节数前移流中的位置,并监视取消请求。

(继承自 Stream)
ReadByte()

从流中读取一个字节,并将流内的位置向前提升一个字节,或者如果已到达流结尾,则返回 -1。

(继承自 Stream)
ReadExactly(Byte[], Int32, Int32)

count从当前流中读取字节数,并推进流中的位置。

(继承自 Stream)
ReadExactly(Span<Byte>)

从当前流中读取字节,并推进流中的位置, buffer 直到 填充 。

(继承自 Stream)
ReadExactlyAsync(Byte[], Int32, Int32, CancellationToken)

从当前流异步读取 count 字节数,推进流中的位置,并监视取消请求。

(继承自 Stream)
ReadExactlyAsync(Memory<Byte>, CancellationToken)

从当前流异步读取字节,推进流中的位置,直到 buffer 填充,并监视取消请求。

(继承自 Stream)
Seek(Int64, SeekOrigin)

引发 NotSupportedException

SetLength(Int64)

设置基础流的长度。

ToString()

返回表示当前对象的字符串。

(继承自 Object)
Write(Byte[], Int32, Int32)

使用指定的缓冲区和偏移将指定数目的 Byte 写入基础流。

Write(ReadOnlySpan<Byte>)

当在派生类中重写时,向当前流中写入字节序列,并将此流中的当前位置提升写入的字节数。

(继承自 Stream)
WriteAsync(Byte[], Int32, Int32)

将字节序列异步写入当前流,并将流的当前位置提升写入的字节数。

(继承自 Stream)
WriteAsync(Byte[], Int32, Int32, CancellationToken)

将指定数量的 Byte 异步写入基础流。

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

将字节的序列异步写入当前流,将该流中的当前位置向前移动写入的字节数,并监视取消请求。

(继承自 Stream)
WriteAsync(ReadOnlyMemory<Byte>, CancellationToken)

将指定数量的 Byte 异步写入基础流。

WriteAsync(ReadOnlyMemory<Byte>, CancellationToken)

将字节的序列异步写入当前流,将该流中的当前位置向前移动写入的字节数,并监视取消请求。

(继承自 Stream)
WriteByte(Byte)

将一个字节写入流内的当前位置,并将流内的位置向前提升一个字节。

(继承自 Stream)

扩展方法

ConfigureAwait(IAsyncDisposable, Boolean)

配置如何执行从异步可处置项返回的任务的等待。

适用于

另请参阅