语言

NegotiateStream 构造函数

定义

初始化 NegotiateStream 类的新实例。

重载

名称 说明
NegotiateStream(Stream)

使用指定的NegotiateStream值初始化类的新实例Stream。

NegotiateStream(Stream, Boolean)

使用指定的NegotiateStream和流关闭行为初始化类的新实例Stream。

注解

若要防止 NegotiateStream 关闭你提供的流,请使用 NegotiateStream(Stream, Boolean) 构造函数。

NegotiateStream(Stream)

Source:
NegotiateStream.cs
Source:
NegotiateStream.cs
Source:
NegotiateStream.cs
Source:
NegotiateStream.cs
Source:
NegotiateStream.cs

使用指定的NegotiateStream值初始化类的新实例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)

参数

innerStream
Stream

Stream用于发送和接收数据的对象NegotiateStream。

示例

下面的代码示例演示如何调用此构造函数。

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

适用于

NegotiateStream(Stream, Boolean)

Source:
NegotiateStream.cs
Source:
NegotiateStream.cs
Source:
NegotiateStream.cs
Source:
NegotiateStream.cs
Source:
NegotiateStream.cs

使用指定的NegotiateStream和流关闭行为初始化类的新实例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)

参数

innerStream
Stream

Stream用于发送和接收数据的对象NegotiateStream。

leaveInnerStreamOpen
Boolean

true 如果指示关闭此操作 NegotiateStream 对它没有影响 innerStream, false 则表示关闭此操作 NegotiateStream 也会关闭 innerStream。

例外

innerStream 是 null。

-或-

innerStream 等于 Null.

示例

以下示例演示如何调用此构造函数。 该代码示例是 NegotiateStream 类中的一个较大示例的一部分。

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

注解

指定trueleaveStreamOpen参数时,关闭该NegotiateStream流不会影响innerStream流;如果不再需要该参数,则必须显式关闭innerStream。

适用于