/// <summary>
        /// <see cref="IHealthServiceResponseParser.ParseResponseAsync"/>
        /// </summary>
        public async Task <HealthServiceResponseData> ParseResponseAsync(HttpResponseMessage response)
        {
            using (Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
            {
                using (var reader = new StreamReader(responseStream, Encoding.UTF8, false, 1024))
                {
                    HealthServiceResponseData result =
                        new HealthServiceResponseData {
                        ResponseHeaders = response.Headers
                    };

                    XmlReaderSettings settings = SDKHelper.XmlReaderSettings;
                    settings.CloseInput       = false;
                    settings.IgnoreWhitespace = false;

                    XmlReader xmlReader = XmlReader.Create(reader, settings);
                    xmlReader.NameTable.Add("wc");

                    if (!SDKHelper.ReadUntil(xmlReader, "code"))
                    {
                        throw new MissingFieldException("code");
                    }

                    result.CodeId = xmlReader.ReadElementContentAsInt();

                    if (result.Code == HealthServiceStatusCode.Ok)
                    {
                        if (xmlReader.ReadToFollowing("wc:info"))
                        {
                            result.InfoNavigator = new XPathDocument(xmlReader).CreateNavigator();
                            result.InfoNavigator.MoveToFirstChild();
                        }

                        return(result);
                    }

                    result.Error = HandleErrorResponse(xmlReader);

                    HealthServiceException healthServiceException =
                        HealthServiceExceptionHelper.GetHealthServiceException(result);

                    throw healthServiceException;
                }
            }
        }
        private HealthServiceResponseError HandleErrorResponse(XmlReader reader)
        {
            HealthServiceResponseError error = new HealthServiceResponseError();

            // <error>
            if (string.Equals(reader.Name, "error", StringComparison.Ordinal))
            {
                // <message>
                if (!SDKHelper.ReadUntil(reader, "message"))
                {
                    throw new MissingFieldException("message");
                }

                error.Message = reader.ReadElementContentAsString();

                // <context>
                SDKHelper.SkipToElement(reader);
                if (string.Equals(reader.Name, "context", StringComparison.Ordinal))
                {
                    HealthServiceErrorContext errorContext = new HealthServiceErrorContext();

                    // <server-name>
                    if (SDKHelper.ReadUntil(reader, "server-name"))
                    {
                        errorContext.ServerName = reader.ReadElementContentAsString();
                    }
                    else
                    {
                        throw new MissingFieldException("server-name");
                    }

                    // <server-ip>
                    Collection <IPAddress> ipAddresses = new Collection <IPAddress>();

                    SDKHelper.SkipToElement(reader);
                    while (reader.Name.Equals("server-ip", StringComparison.Ordinal))
                    {
                        string    ipAddressString = reader.ReadElementContentAsString();
                        IPAddress ipAddress;
                        if (IPAddress.TryParse(ipAddressString, out ipAddress))
                        {
                            ipAddresses.Add(ipAddress);
                        }

                        SDKHelper.SkipToElement(reader);
                    }

                    errorContext.SetServerIpAddresses(ipAddresses);

                    // <exception>
                    if (reader.Name.Equals("exception", StringComparison.Ordinal))
                    {
                        errorContext.InnerException = reader.ReadElementContentAsString();
                        SDKHelper.SkipToElement(reader);
                    }
                    else
                    {
                        throw new MissingFieldException("exception");
                    }

                    error.Context = errorContext;
                }

                // <error-info>
                if (SDKHelper.ReadUntil(reader, "error-info"))
                {
                    error.ErrorInfo = reader.ReadElementContentAsString();
                    SDKHelper.SkipToElement(reader);
                }
            }

            return(error);
        }