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 方法來要求驗證。 用戶端和選擇性的伺服器會使用 Negotiate 安全性通訊協定進行驗證。 如果用戶端和伺服器都支援 Kerberos 通訊協定,則會使用 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)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
CreateWaitHandle()
已過時。
已過時。

配置 WaitHandle 物件。

(繼承來源 Stream)
Dispose()

釋放 Stream 所使用的所有資源。

(繼承來源 Stream)
Dispose(Boolean)

釋放 NegotiateStream 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

Dispose(Boolean)

釋放 AuthenticatedStream 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

(繼承來源 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()
已過時。

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 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)
ReadByte()

從資料流讀取一個位元組,並將資料流的位置推進一個位元組;如果在資料流末端,則傳回 -1。

(繼承來源 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)

設定如何執行從非同步可處置項目傳回的工作 await。

適用於

另請參閱