Method SslStream.BeginSecureChannel

Initiates an asynchronous request to the server to establish a secure channel.

Syntax

public IAsyncResult BeginSecureChannel(
    AsyncCallback callback,
    object state
);

public IAsyncResult BeginSecureChannel(
    string hostName,
    AsyncCallback callback,
    object state
);
    

Parameters

callback (AsyncCallback)

An AsyncCallback delegate that references the method to invoke when the asynchronous operation is complete. Pass null to indicate that no callback is required.

state (object)

An object that contains state information for this asynchronous operation. This parameter can be a null reference.

hostName (string)

The host name of the server to authenticate.

Return Value

IAsyncResult

An IAsyncResult object that contains information about the asynchronous operation.

Remarks

Use the BeginSecureChannel method to begin establishing a secure channel over a connected stream. This method returns an IAsyncResult object, which you can use to track the progress of the asynchronous operation. When the operation is complete, the specified callback delegate is invoked.

You must call EndSecureChannel on the IAsyncResult object returned by this method to complete the operation and obtain the results. If you do not call EndSecureChannel, the stream will not be authenticated and security will not be enabled.

The hostName parameter is used for server authentication. If omitted, the server name is used from the context.

Note: For synchronous operations, use the AuthenticateAsClient or AuthenticateAsServer methods.
Important: Ensure that you have properly configured SSL certificates on both the client and server to establish a secure channel.

See Also