Beispiel #1
0
        public static FaultException CreateFaultException(this IncomingMessage faultMessage)
        {
            if (!faultMessage.IsFault())
            {
                throw new InvalidOperationException("Message is not a fault.");
            }
            var actionHeader = faultMessage.GetHeader <ActionHeader>();
            var xs           = new XmlSerializer(typeof(Fault));
            var body         = (Fault)xs.Deserialize(faultMessage.GetReaderAtBodyContents());

            return(new FaultException(actionHeader.Action,
                                      body.Reason.TextVersions.First().Value,
                                      body.Code.Value,
                                      ExtractSubcodes(body.Code.Subcode)));
        }
Beispiel #2
0
        public static object GetPayload(this IncomingMessage messageWithPayload, Type expectedType)
        {
            if (messageWithPayload.IsEmpty)
            {
                return(null);
            }
            if (messageWithPayload.IsFault())
            {
                var faultException = messageWithPayload.CreateFaultException();
                throw faultException;
            }
            var bodyReader = messageWithPayload.GetReaderAtBodyContents();

            if (typeof(IXmlSerializable).IsAssignableFrom(expectedType))
            {
                var serializable = (IXmlSerializable)Activator.CreateInstance(expectedType);
                serializable.ReadXml(bodyReader);
                return(serializable);
            }
            var xs = new XmlSerializer(expectedType);

            return(xs.Deserialize(bodyReader));
        }