Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

NegotiateStream.BeginWrite Method

Note: This method is new in the .NET Framework version 2.0.

Begins an asynchronous write operation that writes Bytes from the specified buffer to the stream.

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

public override IAsyncResult BeginWrite (
	byte[] buffer,
	int offset,
	int count,
	AsyncCallback asyncCallback,
	Object asyncState
)
public IAsyncResult BeginWrite (
	byte[] buffer, 
	int offset, 
	int count, 
	AsyncCallback asyncCallback, 
	Object asyncState
)
public override function BeginWrite (
	buffer : byte[], 
	offset : int, 
	count : int, 
	asyncCallback : AsyncCallback, 
	asyncState : Object
) : IAsyncResult

Parameters

buffer

A Byte array that supplies the bytes to be written to the stream.

offset

The zero-based location in buffer at which to begin reading bytes to be written to the stream.

count

An Int32 value that specifies the number of bytes to read from buffer.

asyncCallback

An AsyncCallback delegate that references the method to invoke when the write operation is complete.

asyncState

A user-defined object containing information about the write operation. This object is passed to the asyncCallback delegate when the operation completes.

Return Value

An IAsyncResult object indicating the status of the asynchronous operation.
Exception typeCondition

ArgumentNullException

buffer is a null reference (Nothing in Visual Basic).

ArgumentException

offset is less than 0.

- or -

offset is greater than the length of buffer.

- or -

offset plus count is greater than the length of buffer.

IOException

The write operation failed.

- or -

Encryption is in use, but the data could not be encrypted.

NotSupportedException

There is already a write operation in progress.

ObjectDisposedException

This object has been closed.

InvalidOperationException

Authentication has not occurred.

If encryption, signing, or encryption and signing are enabled, this method reads the data from buffer, encrypts, signs, or encrypts and signs it, and transmits it using the underlying stream. If no security services such as data encryption or signing are in use, this method starts an asynchronous write operation on the underlying stream.

This method is asynchronous and does not block while the operation completes. To block until the operation completes, use the Read method.

The asynchronous read operation must be completed by calling the EndWrite method. Typically, the method is invoked by the asyncCallback delegate. For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously

The NegotiateStream class does not support multiple simultaneous write operations. If you attempt to start a write operation while another write operation is already executing on the same stream, a NotSupportedException exception will be thrown.

You cannot call this method until you have successfully authenticated. To authenticate, call one of the AuthenticateAsClient, BeginAuthenticateAsClient, AuthenticateAsServer, or BeginAuthenticateAsServer methods.

The following code example demonstrates beginning an asynchronous write operation.

// Send a message to the server.
// Encode the test data into a byte array.
byte[] message = Encoding.UTF8.GetBytes("Hello from the client.");
ar = authStream.BeginWrite(message, 0, message.Length,
    new AsyncCallback(EndWriteCallback),
    authStream);

The following method is called when the operation completes.

// The following method is called when the write operation completes.
public static void EndWriteCallback (IAsyncResult ar)
{
    Console.WriteLine("Client ending write operation...");
    NegotiateStream authStream = (NegotiateStream) ar.AsyncState;

    // End the asynchronous operation.
    authStream.EndWrite(ar);
}

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

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

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.