public void DownloadUrl(string url, string outputFile)
        {
            try
            {
                WebRequest request = createGetRequest(url);

                //var request = (HttpWebRequest)WebRequest.Create("www.example.com/ex.json");
                var response    = (HttpWebResponse)request.GetResponse();
                var xmlResponse = new StreamReader(response.GetResponseStream()).ReadToEnd();

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmlResponse);
                XmlNodeList           xnList = doc.FirstChild.ChildNodes;
                AbbyyCloudOCRResponse abbyyCloudOCRResponse = new AbbyyCloudOCRResponse();
                foreach (XmlNode xn in xnList)
                {
                    var          type         = xn.Attributes[0].Value;
                    dynamic      value        = ((XmlElement)xn).InnerText;
                    var          propertyType = typeof(AbbyyCloudOCRResponse).GetProperty(type).PropertyType.Name;
                    PropertyInfo prop         = abbyyCloudOCRResponse.GetType().GetProperty(type, BindingFlags.Public | BindingFlags.Instance);

                    if (null != prop && prop.CanWrite)
                    {
                        switch (propertyType)
                        {
                        case "Int32":
                            value = int.Parse(value);
                            break;

                        case "Boolean":
                            value = bool.Parse(value);
                            break;
                        }
                    }
                    prop.SetValue(abbyyCloudOCRResponse, value, null);
                }


                //  XmlSerializer deserializer = new XmlSerializer(typeof(List<Rootobject>));
                // List<Rootobject> movies;
                //  movies = (List<Rootobject>)deserializer.Deserialize(response.GetResponseStream());

                using (HttpWebResponse result = (HttpWebResponse)request.GetResponse())
                {
                    using (Stream stream = result.GetResponseStream())
                    {
                        // Write result directly to file
                        using (Stream file = File.OpenWrite("D:/passport1.xml"))
                        {
                            copyStream(stream, file);
                        }
                    }
                }
            }
            catch (System.Net.WebException e)
            {
                throw new ProcessingErrorException(e.Message, e);
            }
        }
        /// <summary>
        /// Wait until task finishes and download return AbbyyCloudOCRResponse object
        /// </summary>
        public AbbyyCloudOCRResponse WaitAndGetAbbyyCloudOCRResponse(OcrSdkTask task)
        {
            task = waitForTask(task);
            AbbyyCloudOCRResponse abbyyCloudOCRResponse = new AbbyyCloudOCRResponse();

            if (task.Status == TaskStatus.Completed)
            {
                Console.WriteLine("Processing completed.");
                string url = task.DownloadUrls[0];
                abbyyCloudOCRResponse = DownloadUrl(url);
                Console.WriteLine("Download completed.");
            }
            else
            {
                Console.WriteLine("Error while processing the task");
            }
            return(abbyyCloudOCRResponse);
        }
        public AbbyyCloudOCRResponse DownloadUrl(string url)
        {
            AbbyyCloudOCRResponse abbyyCloudOCRResponse = new AbbyyCloudOCRResponse();

            try
            {
                WebRequest request     = createGetRequest(url);
                var        response    = (HttpWebResponse)request.GetResponse();
                var        xmlResponse = new StreamReader(response.GetResponseStream()).ReadToEnd();

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmlResponse);
                XmlNodeList xnList = doc.FirstChild.ChildNodes;
                foreach (XmlNode xn in xnList)
                {
                    var          type         = xn.Attributes[0].Value;
                    dynamic      value        = ((XmlElement)xn).InnerText;
                    var          propertyType = typeof(AbbyyCloudOCRResponse).GetProperty(type).PropertyType.Name;
                    PropertyInfo prop         = abbyyCloudOCRResponse.GetType().GetProperty(type, BindingFlags.Public | BindingFlags.Instance);

                    if (null != prop && prop.CanWrite)
                    {
                        switch (propertyType)
                        {
                        case "Int32":
                            value = int.Parse(value);
                            break;

                        case "Boolean":
                            value = bool.Parse(value);
                            break;
                        }
                    }
                    prop.SetValue(abbyyCloudOCRResponse, value, null);
                }
            }
            catch (System.Net.WebException e)
            {
                throw new ProcessingErrorException(e.Message, e);
            }
            return(abbyyCloudOCRResponse);
        }