Exemplo n.º 1
0
        private Discography GetDiscography(string url)
        {
            var c = new Discography {List = new List<DiscographyData>()};
              c.List.Add(new DiscographyData());

              try
              {
            var request = WebRequest.Create(url);
            request.Proxy = WebRequest.DefaultWebProxy;
            request.Credentials = CredentialCache.DefaultCredentials; ;
            request.Proxy.Credentials = CredentialCache.DefaultCredentials;
            var response = request.GetResponse();
            var reader = new StreamReader(response.GetResponseStream());

            string json = reader.ReadToEnd();

            Discography tmp;

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
            {
              var settings = new DataContractJsonSerializerSettings { UseSimpleDictionaryFormat = true };

              var serializer = new DataContractJsonSerializer(typeof(Discography), settings);
              tmp = (Discography)serializer.ReadObject(ms);
            }

            return tmp ?? c;
              }
              catch (Exception)
              {
            return c;
              }
        }
Exemplo n.º 2
0
        private Discography GetDiscography(string url)
        {
            var c = new Discography {
                List = new List <DiscographyData>()
            };

            c.List.Add(new DiscographyData());

            try
            {
                var request = WebRequest.Create(url);
                request.Proxy             = WebRequest.DefaultWebProxy;
                request.Credentials       = CredentialCache.DefaultCredentials;;
                request.Proxy.Credentials = CredentialCache.DefaultCredentials;
                var response = request.GetResponse();
                var reader   = new StreamReader(response.GetResponseStream());

                string json = reader.ReadToEnd();

                Discography tmp;

                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
                {
                    var settings = new DataContractJsonSerializerSettings {
                        UseSimpleDictionaryFormat = true
                    };

                    var serializer = new DataContractJsonSerializer(typeof(Discography), settings);
                    tmp = (Discography)serializer.ReadObject(ms);
                }

                return(tmp ?? c);
            }
            catch (Exception)
            {
                return(c);
            }
        }