Edit

Share via


IInputChannel.Receive Method

Definition

Returns a message received by the input channel, if one is available with an interval of time that is explicitly or implicitly defined.

Overloads

Receive()

Returns the message received, if one is available. If a message is not available, blocks for a default interval of time.

Receive(TimeSpan)

Returns the message received, if one is available. If a message is not available, blocks for a specified interval of time.

Remarks

Use the synchronous Receive method when it is acceptable for the current thread to be blocked until it receives the request message or exceeds the interval of time specified by timeout. Use the asynchronous BeginReceive method when you need the application processing to continue without waiting for the request to be received.

The synchronous Receive operation is available with or without an explicit timeout.

If a message is not available, it blocks until one is available or until the timeout is exceeded.

Receive()

Source:
IInputChannel.cs
Source:
IInputChannel.cs
Source:
IInputChannel.cs

Returns the message received, if one is available. If a message is not available, blocks for a default interval of time.

public:
 System::ServiceModel::Channels::Message ^ Receive();
public System.ServiceModel.Channels.Message Receive ();
abstract member Receive : unit -> System.ServiceModel.Channels.Message
Public Function Receive () As Message

Returns

The Message received.

Examples

The following code illustrates how to implement this method:

public Message Receive()
{
    return Receive(DefaultReceiveTimeout);
}

Remarks

Use the synchronous Receive method when it is acceptable for the current thread to be blocked until it receives the request message or exceeds the interval of time specified by timeout. Use the asynchronous BeginReceive method when you want the application processing to continue without waiting for the request to be received.

The synchronous Receive operation is available with or without an explicit timeout.

If a message is not available, it blocks until one is available or until the timeout is exceeded.

Receive can be called multiple times or concurrently. Only one Receive call can complete for each message received.

Applies to

Receive(TimeSpan)

Source:
IInputChannel.cs
Source:
IInputChannel.cs
Source:
IInputChannel.cs

Returns the message received, if one is available. If a message is not available, blocks for a specified interval of time.

public:
 System::ServiceModel::Channels::Message ^ Receive(TimeSpan timeout);
public System.ServiceModel.Channels.Message Receive (TimeSpan timeout);
abstract member Receive : TimeSpan -> System.ServiceModel.Channels.Message
Public Function Receive (timeout As TimeSpan) As Message

Parameters

timeout
TimeSpan

The TimeSpan that specifies how long the receive operation has to complete before timing out and throwing a TimeoutException.

Returns

The Message received.

Exceptions

The specified timeout is exceeded before the operation is completed.

The timeout specified is less than zero.

Examples

The following code illustrates how to implement this method:

public Message Receive(TimeSpan timeout)
{
    Message message;
    while (true)
    {
        message = this.InnerChannel.Receive(timeout);
        if (ProcessReceivedMessage(ref message))
        {
            break;
        }
    }

    return message;
}

Remarks

Use the synchronous Receive method when it is acceptable for the current thread to be blocked until it receives the request message or exceeds the interval of time specified by timeout. Use the asynchronous BeginReceive method when you want the application processing to continue without waiting for the request to be received.

The synchronous Receive operation is available with or without an explicit timeout.

If a message is not available, it blocks until one is available or until the timeout is exceeded.

Receive can be called multiple times or concurrently. Only one Receive call can complete for each message received.

Applies to