public static Exception GetFaultException(string faultString, string via, string contentType)
 {
     if (faultString == "http://schemas.microsoft.com/ws/2006/05/framing/faults/EndpointNotFound")
     {
         return new EndpointNotFoundException(System.ServiceModel.SR.GetString("EndpointNotFound", new object[] { via }));
     }
     if (faultString == "http://schemas.microsoft.com/ws/2006/05/framing/faults/ContentTypeInvalid")
     {
         return new ProtocolException(System.ServiceModel.SR.GetString("FramingContentTypeMismatch", new object[] { contentType, via }));
     }
     if (faultString == "http://schemas.microsoft.com/ws/2006/05/framing/faults/ServiceActivationFailed")
     {
         return new ServiceActivationException(System.ServiceModel.SR.GetString("Hosting_ServiceActivationFailed", new object[] { via }));
     }
     if (faultString == "http://schemas.microsoft.com/ws/2006/05/framing/faults/ConnectionDispatchFailed")
     {
         return new CommunicationException(System.ServiceModel.SR.GetString("Sharing_ConnectionDispatchFailed", new object[] { via }));
     }
     if (faultString == "http://schemas.microsoft.com/ws/2006/05/framing/faults/EndpointUnavailable")
     {
         return new EndpointNotFoundException(System.ServiceModel.SR.GetString("Sharing_EndpointUnavailable", new object[] { via }));
     }
     if (faultString == "http://schemas.microsoft.com/ws/2006/05/framing/faults/MaxMessageSizeExceededFault")
     {
         Exception innerException = new QuotaExceededException(System.ServiceModel.SR.GetString("FramingMaxMessageSizeExceeded"));
         return new CommunicationException(innerException.Message, innerException);
     }
     if (faultString == "http://schemas.microsoft.com/ws/2006/05/framing/faults/UnsupportedMode")
     {
         return new ProtocolException(System.ServiceModel.SR.GetString("FramingModeNotSupportedFault", new object[] { via }));
     }
     if (faultString == "http://schemas.microsoft.com/ws/2006/05/framing/faults/UnsupportedVersion")
     {
         return new ProtocolException(System.ServiceModel.SR.GetString("FramingVersionNotSupportedFault", new object[] { via }));
     }
     if (faultString == "http://schemas.microsoft.com/ws/2006/05/framing/faults/ContentTypeTooLong")
     {
         Exception exception2 = new QuotaExceededException(System.ServiceModel.SR.GetString("FramingContentTypeTooLongFault", new object[] { contentType }));
         return new CommunicationException(exception2.Message, exception2);
     }
     if (faultString == "http://schemas.microsoft.com/ws/2006/05/framing/faults/ViaTooLong")
     {
         Exception exception3 = new QuotaExceededException(System.ServiceModel.SR.GetString("FramingViaTooLongFault", new object[] { via }));
         return new CommunicationException(exception3.Message, exception3);
     }
     if (faultString == "http://schemas.microsoft.com/ws/2006/05/framing/faults/ServerTooBusy")
     {
         return new ServerTooBusyException(System.ServiceModel.SR.GetString("ServerTooBusy", new object[] { via }));
     }
     if (faultString == "http://schemas.microsoft.com/ws/2006/05/framing/faults/UpgradeInvalid")
     {
         return new ProtocolException(System.ServiceModel.SR.GetString("FramingUpgradeInvalid", new object[] { via }));
     }
     return new ProtocolException(System.ServiceModel.SR.GetString("FramingFaultUnrecognized", new object[] { faultString }));
 }
        internal static Exception CreateMaxSentMessageSizeExceededException(long maxMessageSize)
        {
            string message = SR.GetString(SR.MaxSentMessageSizeExceeded, maxMessageSize);
            Exception inner = new QuotaExceededException(message);

            if (TD.MaxSentMessageSizeExceededIsEnabled())
            {
                TD.MaxSentMessageSizeExceeded(message);
            }

            return new CommunicationException(message, inner);
        }
예제 #3
0
 internal void AddMessage(Message message)
 {
     if (!this.bufferedChunks.TryEnqueue(this.receiveTimeout, message))
     {
         //caller should not tell us to buffer another chunk
         QuotaExceededException qeException = new QuotaExceededException(
             String.Format("Number of buffered chunks exceeded MaxBufferedChunks setting which is {0}. Consider increasing the setting or processing received data faster", this.bufferedChunks.MaxLength));
         throw new CommunicationException("Quota error while receiving message", qeException);
     }
 }
예제 #4
0
        void ThrowMaxReceivedMessageSizeExceeded()
        {
            if (TD.MaxReceivedMessageSizeExceededIsEnabled())
            {
                TD.MaxReceivedMessageSizeExceeded(SR.GetString(SR.MaxReceivedMessageSizeExceeded, settings.MaxReceivedMessageSize));
            }

            if (isRequest)
            {
                ThrowHttpProtocolException(SR.GetString(SR.MaxReceivedMessageSizeExceeded, settings.MaxReceivedMessageSize), HttpStatusCode.RequestEntityTooLarge);
            }
            else
            {
                string message = SR.GetString(SR.MaxReceivedMessageSizeExceeded, settings.MaxReceivedMessageSize);
                Exception inner = new QuotaExceededException(message);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(message, inner));
            }
        }
 private static void Deduct(string s, ref int maxSizeOfHeaders)
 {
     int num = s.Length * 2;
     if (num > maxSizeOfHeaders)
     {
         string message = System.ServiceModel.SR.GetString("XmlBufferQuotaExceeded");
         Exception innerException = new QuotaExceededException(message);
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(message, innerException));
     }
     maxSizeOfHeaders -= num;
 }
예제 #6
0
            private ArraySegment<byte> ExtractSessionInformationFromMessage(ArraySegment<byte> messageData)
            {
                if (_isReaderSessionInvalid)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(SR.BinaryEncoderSessionInvalid));
                }

                byte[] buffer = messageData.Array;
                int dictionarySize;
                int headerSize;
                int newOffset;
                int newSize;
                bool throwing = true;
                try
                {
                    IntDecoder decoder = new IntDecoder();
                    headerSize = decoder.Decode(buffer, messageData.Offset, messageData.Count);
                    dictionarySize = decoder.Value;
                    if (dictionarySize > messageData.Count)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(SR.BinaryEncoderSessionMalformed));
                    }
                    newOffset = messageData.Offset + headerSize + dictionarySize;
                    newSize = messageData.Count - headerSize - dictionarySize;
                    if (newSize < 0)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(SR.BinaryEncoderSessionMalformed));
                    }
                    if (dictionarySize > 0)
                    {
                        if (dictionarySize > _remainingReaderSessionSize)
                        {
                            string message = SR.Format(SR.BinaryEncoderSessionTooLarge, _maxSessionSize);
                            if (WcfEventSource.Instance.MaxSessionSizeReachedIsEnabled())
                            {
                                WcfEventSource.Instance.MaxSessionSizeReached(message);
                            }
                            Exception inner = new QuotaExceededException(message);
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(message, inner));
                        }
                        else
                        {
                            _remainingReaderSessionSize -= dictionarySize;
                        }

                        int size = dictionarySize;
                        int offset = messageData.Offset + headerSize;

                        while (size > 0)
                        {
                            decoder.Reset();
                            int bytesDecoded = decoder.Decode(buffer, offset, size);
                            int utf8ValueSize = decoder.Value;
                            offset += bytesDecoded;
                            size -= bytesDecoded;
                            if (utf8ValueSize > size)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(SR.BinaryEncoderSessionMalformed));
                            }
                            string value = Encoding.UTF8.GetString(buffer, offset, utf8ValueSize);
                            offset += utf8ValueSize;
                            size -= utf8ValueSize;
                            _readerSession.Add(_idCounter, value);
                            _idCounter++;
                        }
                    }
                    throwing = false;
                }
                finally
                {
                    if (throwing)
                    {
                        _isReaderSessionInvalid = true;
                    }
                }

                return new ArraySegment<byte>(buffer, newOffset, newSize);
            }
 private void ThrowMaxReceivedMessageSizeExceeded()
 {
     if (this.isRequest)
     {
         this.ThrowHttpProtocolException(System.ServiceModel.SR.GetString("MaxReceivedMessageSizeExceeded", new object[] { this.settings.MaxReceivedMessageSize }), HttpStatusCode.BadRequest);
     }
     else
     {
         string message = System.ServiceModel.SR.GetString("MaxReceivedMessageSizeExceeded", new object[] { this.settings.MaxReceivedMessageSize });
         Exception innerException = new QuotaExceededException(message);
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(message, innerException));
     }
 }
예제 #8
0
 public static Exception GetFaultException(string faultString, string via, string contentType)
 {
     if (faultString == FramingEncodingString.EndpointNotFoundFault)
     {
         return new EndpointNotFoundException(SR.GetString(SR.EndpointNotFound, via));
     }
     else if (faultString == FramingEncodingString.ContentTypeInvalidFault)
     {
         return new ProtocolException(SR.GetString(SR.FramingContentTypeMismatch, contentType, via));
     }
     else if (faultString == FramingEncodingString.ServiceActivationFailedFault)
     {
         return new ServiceActivationException(SR.GetString(SR.Hosting_ServiceActivationFailed, via));
     }
     else if (faultString == FramingEncodingString.ConnectionDispatchFailedFault)
     {
         return new CommunicationException(SR.GetString(SR.Sharing_ConnectionDispatchFailed, via));
     }
     else if (faultString == FramingEncodingString.EndpointUnavailableFault)
     {
         return new EndpointNotFoundException(SR.GetString(SR.Sharing_EndpointUnavailable, via));
     }
     else if (faultString == FramingEncodingString.MaxMessageSizeExceededFault)
     {
         Exception inner = new QuotaExceededException(SR.GetString(SR.FramingMaxMessageSizeExceeded));
         return new CommunicationException(inner.Message, inner);
     }
     else if (faultString == FramingEncodingString.UnsupportedModeFault)
     {
         return new ProtocolException(SR.GetString(SR.FramingModeNotSupportedFault, via));
     }
     else if (faultString == FramingEncodingString.UnsupportedVersionFault)
     {
         return new ProtocolException(SR.GetString(SR.FramingVersionNotSupportedFault, via));
     }
     else if (faultString == FramingEncodingString.ContentTypeTooLongFault)
     {
         Exception inner = new QuotaExceededException(SR.GetString(SR.FramingContentTypeTooLongFault, contentType));
         return new CommunicationException(inner.Message, inner);
     }
     else if (faultString == FramingEncodingString.ViaTooLongFault)
     {
         Exception inner = new QuotaExceededException(SR.GetString(SR.FramingViaTooLongFault, via));
         return new CommunicationException(inner.Message, inner);
     }
     else if (faultString == FramingEncodingString.ServerTooBusyFault)
     {
         return new ServerTooBusyException(SR.GetString(SR.ServerTooBusy, via));
     }
     else if (faultString == FramingEncodingString.UpgradeInvalidFault)
     {
         return new ProtocolException(SR.GetString(SR.FramingUpgradeInvalid, via));
     }
     else
     {
         return new ProtocolException(SR.GetString(SR.FramingFaultUnrecognized, faultString));
     }
 }
 private ArraySegment<byte> ExtractSessionInformationFromMessage(ArraySegment<byte> messageData)
 {
     int num3;
     int num4;
     if (this.isReaderSessionInvalid)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(System.ServiceModel.SR.GetString("BinaryEncoderSessionInvalid")));
     }
     byte[] array = messageData.Array;
     bool flag = true;
     try
     {
         IntDecoder decoder = new IntDecoder();
         int num2 = decoder.Decode(array, messageData.Offset, messageData.Count);
         int num = decoder.Value;
         if (num > messageData.Count)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(System.ServiceModel.SR.GetString("BinaryEncoderSessionMalformed")));
         }
         num3 = (messageData.Offset + num2) + num;
         num4 = (messageData.Count - num2) - num;
         if (num4 < 0)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(System.ServiceModel.SR.GetString("BinaryEncoderSessionMalformed")));
         }
         if (num > 0)
         {
             if (num > this.remainingReaderSessionSize)
             {
                 string message = System.ServiceModel.SR.GetString("BinaryEncoderSessionTooLarge", new object[] { this.maxSessionSize });
                 Exception innerException = new QuotaExceededException(message);
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(message, innerException));
             }
             this.remainingReaderSessionSize -= num;
             int size = num;
             int offset = messageData.Offset + num2;
             while (size > 0)
             {
                 decoder.Reset();
                 int num7 = decoder.Decode(array, offset, size);
                 int count = decoder.Value;
                 offset += num7;
                 size -= num7;
                 if (count > size)
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(System.ServiceModel.SR.GetString("BinaryEncoderSessionMalformed")));
                 }
                 string str2 = Encoding.UTF8.GetString(array, offset, count);
                 offset += count;
                 size -= count;
                 this.readerSession.Add(this.idCounter, str2);
                 this.idCounter++;
             }
         }
         flag = false;
     }
     finally
     {
         if (flag)
         {
             this.isReaderSessionInvalid = true;
         }
     }
     return new ArraySegment<byte>(array, num3, num4);
 }