NegotiateStream Constructor (Stream)

Initializes a new instance of the NegotiateStream class using the specified Stream.

Namespace:  System.Net.Security
Assembly:  System (in System.dll)

public NegotiateStream(
	Stream innerStream
)

Parameters

innerStream
Type: System.IO.Stream

A Stream object used by the NegotiateStream for sending and receiving data.

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 = 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);
// Establish the remote endpoint for the socket.
// For this example, use the local machine.
IPHostEntry* ipHostInfo = Dns::Resolve(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(S"Client connected to {0}.",
    remoteEP);
// 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->ClientAuthenticate(
        dynamic_cast<NetworkCredential*> (CredentialCache::DefaultCredentials), 
        S"",
        ProtectionLevel::EncryptAndSign,
        TokenImpersonationLevel::Impersonation);

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft