NegotiateStream 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 NegotiateStream 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| NegotiateStream(Stream) |
使用指定的 NegotiateStream初始化類別的新實例Stream。 |
| NegotiateStream(Stream, Boolean) |
利用指定的 NegotiateStream 和 串流閉包行為初始化該類別的新Stream實例。 |
備註
為了防止他們 NegotiateStream 關閉你供應的溪流,請使用 NegotiateStream(Stream, Boolean) 建構器。
NegotiateStream(Stream)
使用指定的 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)
利用指定的 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閉合對 不影響;innerStreamfalse表示閉合此NegotiateStream亦閉合。innerStream
例外狀況
範例
以下範例示範呼叫此建構子。 此程式碼範例是本類別更大範例 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。