public void SendResponse(uint requestId, IServiceResponse response)
{
if (response == null) throw new ArgumentNullException("response");
lock (DataLock)
{
// must queue the response if the channel is in the faulted state.
if (State == TcpChannelState.Faulted)
{
m_queuedResponses[requestId] = response;
return;
}
// Utils.Trace("Channel {0}: SendResponse {1}", ChannelId, requestId);
BufferCollection buffers = null;
try
{
// note that the server does nothing if the message limits are exceeded.
bool limitsExceeded = false;
buffers = WriteSymmetricMessage(
TcpMessageType.Message,
requestId,
CurrentToken,
response,
false,
out limitsExceeded);
}
catch (Exception e)
{
SendServiceFault(
CurrentToken,
requestId,
ServiceResult.Create(e, StatusCodes.BadEncodingError, "Could not encode outgoing message."));
return;
}
try
{
BeginWriteMessage(buffers, Int32.MaxValue, null);
buffers = null;
}
catch (Exception)
{
if (buffers != null)
{
buffers.Release(BufferManager, "SendResponse");
}
m_queuedResponses[requestId] = response;
return;
}
}
}
#endregion