コード例 #1
0
            //One of the two main entry points into the encoder. Called by WCF to encode a Message into a buffered byte array.
            public override ArraySegment <byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
            {
                //Use the inner encoder to encode a Message into a buffered byte array
                ArraySegment <byte> buffer = innerEncoder.WriteMessage(message, maxMessageSize, bufferManager, 0);

                //Compress the resulting byte array
                return(CompressBuffer(buffer, bufferManager, messageOffset));
            }
コード例 #2
0
        public static void WriteMessage(Message message, IConnection connection, bool isRequest,
                                        IConnectionOrientedTransportFactorySettings settings, ref TimeoutHelper timeoutHelper)
        {
            byte[] endBytes = null;
            if (message != null)
            {
                MessageEncoder messageEncoder     = settings.MessageEncoderFactory.Encoder;
                byte[]         envelopeStartBytes = SingletonEncoder.EnvelopeStartBytes;

                bool writeStreamed;
                if (isRequest)
                {
                    endBytes      = SingletonEncoder.EnvelopeEndFramingEndBytes;
                    writeStreamed = TransferModeHelper.IsRequestStreamed(settings.TransferMode);
                }
                else
                {
                    endBytes      = SingletonEncoder.EnvelopeEndBytes;
                    writeStreamed = TransferModeHelper.IsResponseStreamed(settings.TransferMode);
                }

                if (writeStreamed)
                {
                    connection.Write(envelopeStartBytes, 0, envelopeStartBytes.Length, false, timeoutHelper.RemainingTime());
                    Stream connectionStream   = new StreamingOutputConnectionStream(connection, settings);
                    Stream writeTimeoutStream = new TimeoutStream(connectionStream, timeoutHelper.RemainingTime());
                    messageEncoder.WriteMessage(message, writeTimeoutStream);
                }
                else
                {
                    ArraySegment <byte> messageData = messageEncoder.WriteMessage(message,
                                                                                  int.MaxValue, settings.BufferManager, envelopeStartBytes.Length + IntEncoder.MaxEncodedSize);
                    messageData = SingletonEncoder.EncodeMessageFrame(messageData);
                    Buffer.BlockCopy(envelopeStartBytes, 0, messageData.Array, messageData.Offset - envelopeStartBytes.Length,
                                     envelopeStartBytes.Length);
                    connection.Write(messageData.Array, messageData.Offset - envelopeStartBytes.Length,
                                     messageData.Count + envelopeStartBytes.Length, true, timeoutHelper.RemainingTime(), settings.BufferManager);
                }
            }
            else if (isRequest) // context handles response end bytes
            {
                endBytes = SingletonEncoder.EndBytes;
            }

            if (endBytes != null)
            {
                connection.Write(endBytes, 0, endBytes.Length,
                                 true, timeoutHelper.RemainingTime());
            }
        }
コード例 #3
0
        protected override ArraySegment <byte> EncodeMessage(Message message)
        {
            ArraySegment <byte> messageData = MessageEncoder.WriteMessage(message,
                                                                          int.MaxValue, this.BufferManager, SessionEncoder.MaxMessageFrameSize);

            messageData = SessionEncoder.EncodeMessageFrame(messageData);

            return(messageData);
        }
コード例 #4
0
 public static void WriteMessage(Message message, IConnection connection, bool isRequest, IConnectionOrientedTransportFactorySettings settings, ref TimeoutHelper timeoutHelper)
 {
     byte[] envelopeEndFramingEndBytes = null;
     if (message != null)
     {
         bool           flag;
         MessageEncoder encoder            = settings.MessageEncoderFactory.Encoder;
         byte[]         envelopeStartBytes = SingletonEncoder.EnvelopeStartBytes;
         if (isRequest)
         {
             envelopeEndFramingEndBytes = SingletonEncoder.EnvelopeEndFramingEndBytes;
             flag = TransferModeHelper.IsRequestStreamed(settings.TransferMode);
         }
         else
         {
             envelopeEndFramingEndBytes = SingletonEncoder.EnvelopeEndBytes;
             flag = TransferModeHelper.IsResponseStreamed(settings.TransferMode);
         }
         if (flag)
         {
             connection.Write(envelopeStartBytes, 0, envelopeStartBytes.Length, false, timeoutHelper.RemainingTime());
             Stream stream  = new StreamingOutputConnectionStream(connection, settings);
             Stream stream2 = new TimeoutStream(stream, ref timeoutHelper);
             encoder.WriteMessage(message, stream2);
         }
         else
         {
             ArraySegment <byte> segment = SingletonEncoder.EncodeMessageFrame(encoder.WriteMessage(message, 0x7fffffff, settings.BufferManager, envelopeStartBytes.Length + 5));
             Buffer.BlockCopy(envelopeStartBytes, 0, segment.Array, segment.Offset - envelopeStartBytes.Length, envelopeStartBytes.Length);
             connection.Write(segment.Array, segment.Offset - envelopeStartBytes.Length, segment.Count + envelopeStartBytes.Length, true, timeoutHelper.RemainingTime(), settings.BufferManager);
         }
     }
     else if (isRequest)
     {
         envelopeEndFramingEndBytes = SingletonEncoder.EndBytes;
     }
     if (envelopeEndFramingEndBytes != null)
     {
         connection.Write(envelopeEndFramingEndBytes, 0, envelopeEndFramingEndBytes.Length, true, timeoutHelper.RemainingTime());
     }
 }