private void SerializeResponse(IServerResponseChannelSinkStack sinkStack,
IMessage msg, ref ITransportHeaders headers,
out Stream stream)
{
BaseTransportHeaders responseHeaders = new BaseTransportHeaders();
if (headers != null)
{
// copy old headers into new headers
foreach (DictionaryEntry entry in headers)
{
responseHeaders[entry.Key] = entry.Value;
}
}
headers = responseHeaders;
if (_protocol == Protocol.Http)
{
responseHeaders.ContentType = CoreChannel.BinaryMimeType;
}
bool bMemStream = false;
stream = sinkStack.GetResponseStream(msg, headers);
if (stream == null)
{
stream = new ChunkedMemoryStream(CoreChannel.BufferPool);
bMemStream = true;
}
bool bBashUrl = CoreChannel.SetupUrlBashingForIisSslIfNecessary();
try
{
CallContext.SetData("__ClientIsClr", true);
CoreChannel.SerializeBinaryMessage(msg, stream, _includeVersioning);
}
finally
{
CallContext.FreeNamedDataSlot("__ClientIsClr");
CoreChannel.CleanupUrlBashingForIisSslIfNecessary(bBashUrl);
}
if (bMemStream)
stream.Position = 0;
} // SerializeResponse