private IMessage DeserializeMessage(IMethodCallMessage mcm,
ITransportHeaders headers, Stream stream)
{
IMessage retMsg;
Header[] h = new Header[3];
h[0] = new Header("__TypeName", mcm.TypeName);
h[1] = new Header("__MethodName", mcm.MethodName);
h[2] = new Header("__MethodSignature", mcm.MethodSignature);
String contentTypeHeader = headers["Content-Type"] as String;
String contentTypeValue, charsetValue;
HttpChannelHelper.ParseContentType(contentTypeHeader,
out contentTypeValue, out charsetValue);
if (String.Compare(contentTypeValue, CoreChannel.SOAPMimeType, StringComparison.Ordinal) == 0)
{
// deserialize the message
retMsg = CoreChannel.DeserializeSoapResponseMessage(stream, mcm, h, _strictBinding);
}
else
{
// an error has occurred
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
StringBuilder sb = new StringBuilder();
int readCount = stream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
sb.Append(Encoding.ASCII.GetString(buffer, 0, readCount));
readCount = stream.Read(buffer, 0, bufferSize);
}
retMsg = new ReturnMessage(new RemotingException(sb.ToString()), mcm);
}
// Close the stream since we're done with it (especially important if this
// happened to be a network stream)
stream.Close();
return retMsg;
} // DeserializeMessage