コード例 #1
0
        /// <summary>
        /// Deserializes X-Road message response or throws <see>XRoadFaultException</see> when
        /// X-Road fault is parsed from the message instead of expected result value.
        /// </summary>
        public static object DeserializeMessageContent(this XRoadMessage message, IServiceMap serviceMap, IMessageFormatter messageFormatter)
        {
            if (serviceMap.ResponseDefinition.ContainsNonTechnicalFault)
            {
                ThrowIfXRoadFault(message, serviceMap, messageFormatter);
            }

            message.ContentStream.Position = 0;
            using (var reader = XmlReader.Create(message.ContentStream))
            {
                messageFormatter.MoveToBody(reader);

                if (!reader.MoveToElement(2))
                {
                    throw new InvalidQueryException("No payload element in SOAP message.");
                }

                messageFormatter.ThrowSoapFaultIfPresent(reader);

                var result = serviceMap.DeserializeResponse(reader, message);

                return(result is XRoadFault fault ? throw new XRoadFaultException(fault) : result);
            }
        }