コード例 #1
0
        private static MemoryStream RetrieveImageData(string url, out StreamingResultMetaData result)
        {
            try
            {
                result = new StreamingResultMetaData();

                result.Speed.Start();

                var request = (HttpWebRequest)WebRequest.Create(url.ToString());
                request.Accept    = "application/dicom,application/Macro,application/Macro-header,image/jpeg,application/pdf";
                request.Timeout   = (int)TimeSpan.FromSeconds(StreamingSettings.Default.ClientTimeoutSeconds).TotalMilliseconds;
                request.KeepAlive = false;

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    throw new StreamingClientException(response.StatusCode, HttpUtility.HtmlDecode(response.StatusDescription));
                }

                Stream       responseStream = response.GetResponseStream();
                BinaryReader reader         = new BinaryReader(responseStream);
                byte[]       buffer         = reader.ReadBytes((int)response.ContentLength);
                reader.Close();
                responseStream.Close();
                response.Close();

                result.Speed.SetData(buffer.Length);
                result.Speed.End();

                result.ResponseMimeType  = response.ContentType;
                result.Status            = response.StatusCode;
                result.StatusDescription = response.StatusDescription;
                result.Uri           = response.ResponseUri;
                result.ContentLength = buffer.Length;

                return(new MemoryStream(buffer));
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response is HttpWebResponse)
                {
                    HttpWebResponse response = (HttpWebResponse)ex.Response;
                    throw new StreamingClientException(response.StatusCode, HttpUtility.HtmlDecode(response.StatusDescription));
                }
                throw new StreamingClientException(StreamingClientExceptionType.Network, ex);
            }
        }
コード例 #2
0
        public Stream RetrievePdf(string serverAE, string studyInstanceUID, string seriesInstanceUID, string sopInstanceUid, out StreamingResultMetaData metaInfo)
        {
            string imageUrl = BuildImageUrl(serverAE, studyInstanceUID, seriesInstanceUID, sopInstanceUid);

            imageUrl = imageUrl + String.Format("&contentType={0}", HttpUtility.HtmlEncode("application/pdf"));
            return(RetrieveImageData(imageUrl, out metaInfo));
        }
コード例 #3
0
        public Stream RetrieveImageHeader(string serverAE, string studyInstanceUID, string seriesInstanceUID, string sopInstanceUid, uint stopTag, out StreamingResultMetaData metaInfo)
        {
            string imageUrl = BuildImageUrl(serverAE, studyInstanceUID, seriesInstanceUID, sopInstanceUid);

            imageUrl = imageUrl + String.Format("&stopTag={0:x8}", stopTag);
            imageUrl = imageUrl + String.Format("&contentType={0}", HttpUtility.HtmlEncode("application/Macro-header"));
            return(RetrieveImageData(imageUrl, out metaInfo));
        }