Udostępnij za pośrednictwem


NegotiateStream Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy NegotiateStream.

Przeciążenia

NegotiateStream(Stream)

Inicjuje NegotiateStream nowe wystąpienie klasy przy użyciu określonego Streamelementu .

NegotiateStream(Stream, Boolean)

Inicjuje NegotiateStream nowe wystąpienie klasy przy użyciu określonego zachowania zamknięcia strumienia i określonego Stream .

Uwagi

Aby zapobiec zamykaniu NegotiateStream dostarczanego strumienia, użyj konstruktora NegotiateStream(Stream, Boolean) .

NegotiateStream(Stream)

Źródło:
NegotiateStream.cs
Źródło:
NegotiateStream.cs
Źródło:
NegotiateStream.cs

Inicjuje NegotiateStream nowe wystąpienie klasy przy użyciu określonego Streamelementu .

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)

Parametry

innerStream
Stream

Stream Obiekt używany przez NegotiateStream obiekt do wysyłania i odbierania danych.

Przykłady

W poniższym przykładzie kodu pokazano wywołanie tego konstruktora.

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

Dotyczy

NegotiateStream(Stream, Boolean)

Źródło:
NegotiateStream.cs
Źródło:
NegotiateStream.cs
Źródło:
NegotiateStream.cs

Inicjuje NegotiateStream nowe wystąpienie klasy przy użyciu określonego zachowania zamknięcia strumienia i określonego 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)

Parametry

innerStream
Stream

Stream Obiekt używany przez NegotiateStream obiekt do wysyłania i odbierania danych.

leaveInnerStreamOpen
Boolean

true aby wskazać, że zamknięcie tego NegotiateStream elementu nie ma wpływu na innerStream; false aby wskazać, że zamknięcie tego NegotiateStream elementu również powoduje zamknięcie innerStreamelementu .

Wyjątki

innerStream to null.

-lub-

innerStream jest równe Null.

Przykłady

W poniższym przykładzie pokazano wywołanie tego konstruktora. Ten przykład kodu jest częścią większego przykładu udostępnionego NegotiateStream dla klasy .

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

Uwagi

Po określeniu true parametru leaveStreamOpen zamknięcie NegotiateStream elementu nie ma wpływu na innerStream strumień; należy jawnie zamknąć innerStream , gdy nie jest już potrzebny.

Dotyczy