internal ChunkingReader(Message startMessage, int maxBufferedChunks, TimeoutHelper receiveTimeout) { //set innerReader this.innerReader = startMessage.GetReaderAtBodyContents(); this.lockobject = new object(); this.messageId = ChunkingUtils.GetMessageHeader <Guid>(startMessage, ChunkingUtils.MessageIdHeader, ChunkingUtils.ChunkNs); this.bufferedChunks = new SynchronizedQueue <Message>(maxBufferedChunks); this.receiveTimeout = receiveTimeout; this.nextChunkNum = 1; }
private void SetStartMessageHeaders(Message message, Message chunk) { this.messageId = Guid.NewGuid(); //create messageId header this.messageIdHeader = MessageHeader.CreateHeader( ChunkingUtils.MessageIdHeader, ChunkingUtils.ChunkNs, this.messageId.ToString(), true); chunk.Headers.Add(this.messageIdHeader); //create chunkStart header MessageHeader chunkStartHeader = MessageHeader.CreateHeader( ChunkingUtils.ChunkingStartHeader, ChunkingUtils.ChunkNs, null, true); chunk.Headers.Add(chunkStartHeader); //write out original headers as new message's headers MessageHeaders headers = message.Headers; string addressingNs = ChunkingUtils.GetAddressingNamespace(message.Version); for (int i = 0; i < headers.Count; i++) { //look for Action header and write it out as OriginalAction if (headers[i].Name == "Action" && headers[i].Namespace == addressingNs) { //write out original action string originalAction = message.Headers.Action; //headers.GetHeader<string>(i); MessageHeader originalActionHeader = MessageHeader.CreateHeader(ChunkingUtils.OriginalAction, ChunkingUtils.ChunkNs, originalAction); chunk.Headers.Add(originalActionHeader); } else { //copying a header chunk.Headers.CopyHeaderFrom(headers, i); } } }
ChunkingMessage GetNewChunkingMessage(Message receivedMessage, TimeoutHelper timeoutHelper) { if (receivedMessage == null) { //end of session return(null); } Guid messageId = GetMessageId(receivedMessage); if (this.currentInputMessage != null && messageId == this.currentInputMessage.MessageId) { throw new InvalidOperationException("A new ChunkingMessage was requested but the received message's id matches the current message id. The received message is a chunk of the current message"); } ChunkingReader reader = new ChunkingReader(receivedMessage, this.maxBufferedChunks, timeoutHelper); string originalAction = receivedMessage.Headers.GetHeader <string>( ChunkingUtils.OriginalAction, ChunkingUtils.ChunkNs); ChunkingMessage dechunkedMessage = new ChunkingMessage(receivedMessage.Version, originalAction, reader, messageId); string addressingNs = ChunkingUtils.GetAddressingNamespace(receivedMessage.Version); //read original headers from body of startingChunk and add them to headers of dechunkedMessage for (int i = 0; i < receivedMessage.Headers.Count; i++) { MessageHeaderInfo headerInfo = receivedMessage.Headers[i]; if (headerInfo.Namespace != ChunkingUtils.ChunkNs && !(headerInfo.Name == "Action" && headerInfo.Namespace == addressingNs)) { //not a chunking header and not the chunking wsa:Action header //copy it to dechunkedMessage dechunkedMessage.Headers.CopyHeaderFrom( receivedMessage.Headers, i); } } return(dechunkedMessage); }