public static MessageFault CreateFault(Message message, int maxBufferSize)
        {
            MessageFault fault2;

            if (message == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message"));
            }
            XmlDictionaryReader readerAtBodyContents = message.GetReaderAtBodyContents();
            XmlDictionaryReader reader2 = readerAtBodyContents;

            try
            {
                MessageFault    fault;
                EnvelopeVersion envelope = message.Version.Envelope;
                if (envelope == EnvelopeVersion.Soap12)
                {
                    fault = ReceivedFault.CreateFault12(readerAtBodyContents, maxBufferSize);
                }
                else if (envelope == EnvelopeVersion.Soap11)
                {
                    fault = ReceivedFault.CreateFault11(readerAtBodyContents, maxBufferSize);
                }
                else
                {
                    if (envelope != EnvelopeVersion.None)
                    {
                        throw TraceUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("EnvelopeVersionUnknown", new object[] { envelope.ToString() })), message);
                    }
                    fault = ReceivedFault.CreateFaultNone(readerAtBodyContents, maxBufferSize);
                }
                message.ReadFromBodyContentsToEnd(readerAtBodyContents);
                fault2 = fault;
            }
            catch (InvalidOperationException exception)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SFxErrorDeserializingFault"), exception));
            }
            catch (FormatException exception2)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SFxErrorDeserializingFault"), exception2));
            }
            catch (XmlException exception3)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SFxErrorDeserializingFault"), exception3));
            }
            finally
            {
                if (reader2 != null)
                {
                    reader2.Dispose();
                }
            }
            return(fault2);
        }
Beispiel #2
0
        public static MessageFault CreateFault(Message message, int maxBufferSize)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(message)));
            }

            XmlDictionaryReader reader = message.GetReaderAtBodyContents();

            using (reader)
            {
                try
                {
                    EnvelopeVersion envelopeVersion = message.Version.Envelope;
                    MessageFault    fault;
                    if (envelopeVersion == EnvelopeVersion.Soap12)
                    {
                        fault = ReceivedFault.CreateFault12(reader, maxBufferSize);
                    }
                    else if (envelopeVersion == EnvelopeVersion.Soap11)
                    {
                        fault = ReceivedFault.CreateFault11(reader, maxBufferSize);
                    }
                    else if (envelopeVersion == EnvelopeVersion.None)
                    {
                        fault = ReceivedFault.CreateFaultNone(reader, maxBufferSize);
                    }
                    else
                    {
                        throw TraceUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.EnvelopeVersionUnknown, envelopeVersion.ToString())), message);
                    }
                    message.ReadFromBodyContentsToEnd(reader);
                    return(fault);
                }
                catch (InvalidOperationException e)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                                  SR.SFxErrorDeserializingFault, e));
                }
                catch (FormatException e)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                                  SR.SFxErrorDeserializingFault, e));
                }
                catch (XmlException e)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                                  SR.SFxErrorDeserializingFault, e));
                }
            }
        }