开发者

I am trying to run Mars Image Viewer Sample from OCT 2010 MSDN Magazine but running into some errors?

Here is the code-

private void getImageIDs()
        {
            Ur开发者_JAVA百科i serviceUri = new Uri("https://api.sqlazureservices.com/NasaService.svc/MER/Images?missionId=1&$format=raw");
            WebClient recDownloader = new WebClient();
            recDownloader.Headers["$accountKey"] = "<enter your key>";
            recDownloader.Headers["$uniqueUserID"] = "<enter your id>";
            recDownloader.OpenReadCompleted += new OpenReadCompletedEventHandler(recDownloader_OpenReadCompleted);
            recDownloader.OpenReadAsync(serviceUri);            
        }

        private void recDownloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                Stream responseStream = e.Result;
                XNamespace ns = "http://www.w3.org/2005/Atom";
                XElement marsStuff = XElement.Load(responseStream);
                entries = marsStuff.Elements(ns + "entry");
                string imageID = (string)entries.ElementAt<XElement>(index).Element(ns + "title").Value;
                Console.WriteLine(imageID);
                getImage(imageID);                   
            }
        }

        private void getImage(string ID)
        {
            Uri serviceUri = new Uri("https://api.sqlazureservices.com/NasaService.svc/MER/Images/" + ID + "?$format=raw");
            WebClient imgDownloader = new WebClient();
            imgDownloader.Headers["$accountKey"] = "<enter your key>";
            imgDownloader.Headers["$uniqueUserID"] = "<enter your id>";
            imgDownloader.OpenReadCompleted += new OpenReadCompletedEventHandler(imgDownloader_OpenReadCompleted);
            imgDownloader.OpenReadAsync(serviceUri);
        }

        private void imgDownloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                Stream imageStream = e.Result;
                BitmapImage imgsrc = new BitmapImage();
                imgsrc.SetSource(imageStream);
                MarsImage.Source = imgsrc;
            }
        }

        private void appbar_BackButton_Click(object sender, EventArgs e)
        {
            if (index > 0)
            {
                index--;
                XNamespace ns = "http://www.w3.org/2005/Atom";
                string imageID = (string)entries.ElementAt<XElement>(index).Element(ns + "Title").Value;
                getImage(imageID);
            }
        }

        private void appbar_ForwardButton_Click(object sender, EventArgs e)
        {
            if ( (index + 1) < entries.Count<XElement>())
            {
                index++;
                XNamespace ns = "http://www.w3.org/2005/Atom";
                string imageID = (string)entries.ElementAt<XElement>(index).Element(ns + "Title").Value;
                getImage(imageID);
            }
        }
    }

I am not seeing any images. Anybody able to get this sample running?


This one? http://msdn.microsoft.com/en-us/magazine/gg232764.aspx

If so, there are some things that had to change to make it work, as the original code was on a preview version of the WP7 tools, as listed in the comments there:

Delete (or comment out) the following lines of code from MainPage.xaml.cs        
recDownloader.Headers["$accountKey"] = "<Your account key>";    
recDownloader.Headers["$uniqueUserID"] = "<Your user ID>";
imgDownloader.Headers["$accountKey"] = "<Your account key>";
imgDownloader.Headers["$uniqueUserID"] = "<Your user ID>";

Replace the two recDownloader lines of code with:

recDownloader.Credentials = new NetworkCredential("accountKey", "<Your account key>");   

Replace the two imgDownloader lines of code with:

imgDownloader.Credentials = new NetworkCredential("accountKey", "<Your account key>");   
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜