NegotiateStream Construtores

Definição

Inicializa uma nova instância da classe NegotiateStream.

Sobrecargas

Nome Description
NegotiateStream(Stream)

Inicializa uma nova instância da NegotiateStream classe usando a especificada Stream.

NegotiateStream(Stream, Boolean)

Inicializa uma nova instância da NegotiateStream classe usando o comportamento de fechamento de fluxo e especificado Stream .

Comentários

Para impedir o NegotiateStream fechamento do fluxo fornecido, use o NegotiateStream(Stream, Boolean) construtor.

NegotiateStream(Stream)

Inicializa uma nova instância da NegotiateStream classe usando a especificada 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

Um Stream objeto usado pelo NegotiateStream envio e recebimento de dados.

Exemplos

O exemplo de código a seguir demonstra a chamada desse construtor.

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

Aplica-se a

NegotiateStream(Stream, Boolean)

Inicializa uma nova instância da NegotiateStream classe usando o comportamento de fechamento de fluxo e 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

Um Stream objeto usado pelo NegotiateStream envio e recebimento de dados.

leaveInnerStreamOpen
Boolean

true para indicar que fechar isso NegotiateStream não tem nenhum efeito em innerStream; false para indicar que fechar isso NegotiateStream também fecha innerStream.

Exceções

innerStream é null.

-ou-

innerStream é igual a Null.

Exemplos

O exemplo a seguir demonstra a chamada desse construtor. Este exemplo de código faz parte de um exemplo maior fornecido para a NegotiateStream classe.

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

Comentários

Quando você especificar true para o leaveStreamOpen parâmetro, fechar o NegotiateStream não tem efeito no innerStream fluxo; você deve fechar innerStream explicitamente quando não precisar mais dele.

Aplica-se a