NegotiateStream Konstruktorer

Definition

Initierar en ny instans av NegotiateStream klassen.

Överlagringar

Name Description
NegotiateStream(Stream)

Initierar en ny instans av NegotiateStream klassen med den angivna Stream.

NegotiateStream(Stream, Boolean)

Initierar en ny instans av klassen med hjälp av NegotiateStream det angivna Stream och strömmande stängningsbeteendet.

Kommentarer

Om du vill förhindra att NegotiateStream dataströmmen som du anger stängs använder NegotiateStream(Stream, Boolean) du konstruktorn.

NegotiateStream(Stream)

Initierar en ny instans av NegotiateStream klassen med den angivna 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)

Parametrar

innerStream
Stream

Ett Stream objekt som används av NegotiateStream för att skicka och ta emot data.

Exempel

Följande kodexempel visar hur du anropar den här konstruktorn.

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

Gäller för

NegotiateStream(Stream, Boolean)

Initierar en ny instans av klassen med hjälp av NegotiateStream det angivna Stream och strömmande stängningsbeteendet.

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)

Parametrar

innerStream
Stream

Ett Stream objekt som används av NegotiateStream för att skicka och ta emot data.

leaveInnerStreamOpen
Boolean

true för att indikera att stängning av detta NegotiateStream inte har någon effekt på innerStream; false för att indikera att stängning av detta NegotiateStream också stänger innerStream.

Undantag

innerStream är null.

-eller-

innerStream är lika med Null.

Exempel

I följande exempel visas hur du anropar den här konstruktorn. Det här kodexemplet är en del av ett större exempel för NegotiateStream klassen.

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

Kommentarer

När du anger true för parametern leaveStreamOpen har stängningen NegotiateStream inte någon effekt på innerStream strömmen. Du måste uttryckligen stänga innerStream när du inte längre behöver den.

Gäller för