internal static void LogResponse(HealthServiceResponseData response) { string responseString = String.Empty; string infoXml = (response.InfoNavigator != null) ? response.InfoNavigator.OuterXml : String.Empty; if (response.Error == null) { responseString = String.Join( String.Empty, new string[] { "Code:", response.Code.ToString(), "|Info:", infoXml }); } else { responseString = String.Join(String.Empty, new string[] { "Code:", response.Code.ToString(), "|Error:", response.Error.ToString(), "|Info:", infoXml }); } s_traceSource.TraceInformation(responseString); }
/// <summary> /// Handles the data retrieved by making the web request. /// </summary> /// /// <param name="stream"> /// The response stream from the web request. /// </param> /// /// <exception cref ="HealthServiceException"> /// HealthVault returns an exception in the form of an /// exception section in the response XML. /// </exception> /// public static HealthServiceResponseData HandleResponseStreamResult( Stream stream) { HealthServiceResponseData result = new HealthServiceResponseData(); MemoryStream responseStream = stream as MemoryStream; if (responseStream == null) { try { responseStream = new MemoryStream(); int count; Byte[] buff = new Byte[1024 * 2]; while ((count = stream.Read(buff, 0, buff.Length)) > 0) { responseStream.Write(buff, 0, count); } responseStream.Flush(); } finally { stream.Close(); stream = null; } } if (HealthVaultPlatformTrace.LoggingEnabled) { HealthVaultPlatformTrace.LogResponse( Encoding.UTF8.GetString(responseStream.GetBuffer(), 0, (int)responseStream.Length)); } XmlReaderSettings settings = SDKHelper.XmlReaderSettings; settings.CloseInput = false; settings.IgnoreWhitespace = false; responseStream.Position = 0; XmlReader reader = XmlReader.Create(responseStream, settings); reader.NameTable.Add("wc"); if (!SDKHelper.ReadUntil(reader, "code")) throw new MissingFieldException("response", "code"); result.CodeId = reader.ReadElementContentAsInt(); if (result.Code == HealthServiceStatusCode.Ok) { if (reader.ReadToFollowing("wc:info")) { result.InfoReader = reader; byte[] buff = responseStream.GetBuffer(); int offset = 0; int count = (int)responseStream.Length; while (offset < count && buff[offset] != '<') { offset++; } result.ResponseText = new ArraySegment<Byte>(buff, offset, count - offset); } return result; } result.Error = HandleErrorResponse(reader); HealthServiceException e = HealthServiceExceptionHelper.GetHealthServiceException(result.CodeId, result.Error); throw e; }
/// <summary> /// Represents the <see cref="IEasyWebResponseHandler"/> callback. /// </summary> /// /// <param name="stream"> /// The response stream. /// </param> /// /// <exception cref ="HealthServiceException"> /// HealthVault returns an exception in the form of an /// exception section in the response XML. /// </exception> /// public void HandleResponseStream(Stream stream) { if (_responseStreamHandler != null) { _responseStreamHandler(stream); } else { _response = HandleResponseStreamResult(stream); } }
public void HandleResponseStream(Stream stream) { _response = HealthServiceRequest.HandleResponseStreamResult(stream); }