NegotiateStream Constructores

Definición

Inicializa una nueva instancia de la clase NegotiateStream.

Sobrecargas

Nombre Description
NegotiateStream(Stream)

Inicializa una nueva instancia de la NegotiateStream clase utilizando el especificado Stream.

NegotiateStream(Stream, Boolean)

Inicializa una nueva instancia de la NegotiateStream clase utilizando el comportamiento de cierre de flujo y especificado Stream .

Comentarios

Para evitar que NegotiateStream cierre la secuencia que proporcione, use el NegotiateStream(Stream, Boolean) constructor .

NegotiateStream(Stream)

Inicializa una nueva instancia de la NegotiateStream clase utilizando el especificado 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)

Parámetros

innerStream
Stream

Objeto Stream utilizado por para NegotiateStream enviar y recibir datos.

Ejemplos

En el ejemplo de código siguiente se muestra cómo llamar a este 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 = 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);

Se aplica a

NegotiateStream(Stream, Boolean)

Inicializa una nueva instancia de la NegotiateStream clase utilizando el comportamiento de cierre de flujo y especificado Stream .

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)

Parámetros

innerStream
Stream

Objeto Stream utilizado por para NegotiateStream enviar y recibir datos.

leaveInnerStreamOpen
Boolean

true para indicar que el cierre no NegotiateStream tiene ningún efecto en innerStream; false para indicar que al cerrar esto NegotiateStream también se innerStreamcierra .

Excepciones

innerStream es null.

O bien

innerStream es igual a Null.

Ejemplos

En el ejemplo siguiente se muestra cómo llamar a este constructor. Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la NegotiateStream clase .

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

Comentarios

Cuando se especifica true para el leaveStreamOpen parámetro , el cierre NegotiateStream no tiene ningún efecto en la innerStream secuencia; debe cerrarse innerStream explícitamente cuando ya no lo necesite.

Se aplica a