NegotiateStream Konstruktoren

Definition

Initialisiert eine neue Instanz der NegotiateStream-Klasse.Initializes a new instance of the NegotiateStream class.

Überlädt

NegotiateStream(Stream)

Initialisiert eine neue Instanz der NegotiateStream-Klasse mit dem angegebenen Stream.Initializes a new instance of the NegotiateStream class using the specified Stream.

NegotiateStream(Stream, Boolean)

Verwendet den angegebenen NegotiateStream und das Schlussverhalten des Streams zum Initialisieren einer neuen Instanz der Stream-Klasse.Initializes a new instance of the NegotiateStream class using the specified Stream and stream closure behavior.

Hinweise

Verwenden Sie den Konstruktor NegotiateStream(Stream, Boolean), um zu verhindern, dass der von Ihnen bereitgestellte Stream durch NegotiateStream geschlossen wird.To prevent the NegotiateStream from closing the stream that you supply, use the NegotiateStream(Stream, Boolean) constructor.

NegotiateStream(Stream)

Initialisiert eine neue Instanz der NegotiateStream-Klasse mit dem angegebenen Stream.Initializes a new instance of the NegotiateStream class using the specified Stream.

public:
 NegotiateStream(System::IO::Stream ^ innerStream);
public NegotiateStream (System.IO.Stream innerStream);
new System.Net.Security.NegotiateStream : System.IO.Stream -> System.Net.Security.NegotiateStream
Public Sub New (innerStream As Stream)

Parameter

innerStream
Stream

Ein Stream-Objekt, das von NegotiateStream zum Senden und Empfangen von Daten verwendet wird.A Stream object used by the NegotiateStream for sending and receiving data.

Beispiele

Im folgenden Codebeispiel wird das Aufrufen dieses Konstruktors veranschaulicht.The following code example demonstrates calling this constructor.

// 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.
TcpClient^ 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 );

// Request authentication for the client only (no mutual authentication).
// Authenicate using the client's default credetials.
// Permit the server to impersonate the client to access resources on the server only.
// Request that data be transmitted using encryption and data signing.
authStream->AuthenticateAsClient( dynamic_cast<NetworkCredential^>(CredentialCache::DefaultCredentials), 
       L"", 
       ProtectionLevel::EncryptAndSign, 
       TokenImpersonationLevel::Impersonation );

 // 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 = new IPEndPoint(ipAddress,11000);
 // Create a TCP/IP socket.
TcpClient 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); 
 // Request authentication for the client only (no mutual authentication).
 // Authenicate using the client's default credetials.
 // Permit the server to impersonate the client to access resources on the server only.
 // Request that data be transmitted using encryption and data signing.
 authStream.AuthenticateAsClient(
      (NetworkCredential) CredentialCache.DefaultCredentials, 
      "",
      ProtectionLevel.EncryptAndSign,
      TokenImpersonationLevel.Impersonation);

NegotiateStream(Stream, Boolean)

Verwendet den angegebenen NegotiateStream und das Schlussverhalten des Streams zum Initialisieren einer neuen Instanz der Stream-Klasse.Initializes a new instance of the NegotiateStream class using the specified Stream and stream closure behavior.

public:
 NegotiateStream(System::IO::Stream ^ innerStream, bool leaveInnerStreamOpen);
public NegotiateStream (System.IO.Stream innerStream, bool leaveInnerStreamOpen);
new System.Net.Security.NegotiateStream : System.IO.Stream * bool -> System.Net.Security.NegotiateStream
Public Sub New (innerStream As Stream, leaveInnerStreamOpen As Boolean)

Parameter

innerStream
Stream

Ein Stream-Objekt, das von NegotiateStream zum Senden und Empfangen von Daten verwendet wird.A Stream object used by the NegotiateStream for sending and receiving data.

leaveInnerStreamOpen
Boolean

true, um anzugeben, dass das Schließen dieses NegotiateStream keine Auswirkungen auf innerStream hat. false, um anzugeben, dass durch Schließen dieses NegotiateStream auch innerStream geschlossen wird.true to indicate that closing this NegotiateStream has no effect on innerStream; false to indicate that closing this NegotiateStream also closes innerStream.

Ausnahmen

innerStream ist null.innerStream is null.

- oder --or- innerStream ist gleich Null.innerStream is equal to Null.

Beispiele

Im folgenden Beispiel wird der Aufruf dieses Konstruktors veranschaulicht.The following example demonstrates calling this constructor. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die NegotiateStream-Klasse bereitgestellt wird.This code example is part of a larger example provided for the NegotiateStream class.

// 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 );

// 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); 
' 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)

Hinweise

Wenn Sie true für den Parameter leaveStreamOpen angeben, hat das Schließen der NegotiateStream keine Auswirkung auf den innerStream Datenstrom. Sie müssen innerStream explizit schließen, wenn Sie ihn nicht mehr benötigen.When you specify true for the leaveStreamOpen parameter, closing the NegotiateStream has no effect on the innerStream stream; you must explicitly close innerStream when you no longer need it.

Gilt für: