{"id":663,"date":"2012-08-23T10:59:00","date_gmt":"2012-08-23T10:59:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/odatateam\/2012\/08\/23\/odata-101-building-our-first-odata-based-windows-store-app-part-1\/"},"modified":"2024-02-12T16:26:47","modified_gmt":"2024-02-12T23:26:47","slug":"odata-101-building-our-first-odata-based-windows-store-app-part-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/odata\/odata-101-building-our-first-odata-based-windows-store-app-part-1\/","title":{"rendered":"OData 101: Building our first OData-based Windows Store app (Part 1)"},"content":{"rendered":"<p><a href=\"https:\/\/www.bitwhys.com\/assets\/OData.WindowsStore.NetflixDemo.zip\">Download the sample code<\/a><\/p>\n<p>In this OData 101 we will build a Windows Store app that consumes and displays movies from the Netflix OData feed. Specifically, we will focus on getting data, displaying it in the default grid layout, and enabling search functionality.<\/p>\n<p>Because there&rsquo;s a lot of details to talk about in this blog post, we&rsquo;ll walk through the actual steps to get the application functional first, and we&rsquo;ll walk through some of the code in a <a href=\"http:\/\/blogs.msdn.com\/b\/astoriateam\/archive\/2012\/08\/23\/odata-101-building-our-first-odata-based-windows-store-app-part-2.aspx\">subsequent post<\/a>.<\/p>\n<p>Before you get started, you should ensure that you have an RTM version of <a href=\"http:\/\/www.microsoft.com\/visualstudio\/\" target=\"_blank\" rel=\"noopener\">Visual Studio<\/a> 2012 and have downloaded and installed the <a href=\"https:\/\/go.microsoft.com\/fwlink\/?LinkId=253653\" target=\"_blank\" rel=\"noopener\">WCF Data Services Tools for Windows Store Apps<\/a>.<\/p>\n<p>1. Let&rsquo;s start by creating a new <strong>Windows Store Grid App<\/strong> using C#\/XAML. Name the application <strong>OData.WindowsStore.NetflixDemo<\/strong>:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/2100.image_thumb_17F420AE.png\"><img decoding=\"async\" width=\"644\" height=\"446\" title=\"image\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/2100.image_thumb_17F420AE.png\" border=\"0\" \/><\/a><\/p>\n<p>2. [Optional]: Open the <strong>Package.appxmanifest<\/strong> and assign a friendly name to the <strong>Display name<\/strong>. This will make an impact when we get around to adding the search contract:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/8463.image_thumb_7E8C1D73.png\"><img decoding=\"async\" width=\"644\" height=\"301\" title=\"image\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/8463.image_thumb_7E8C1D73.png\" border=\"0\" \/><\/a><\/p>\n<p>3. [Optional]: Update the <strong>AppName<\/strong> in <strong>App.xaml<\/strong> to a friendly name. This value will be displayed when the application is launched.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/0636.image_thumb_65241A39.png\"><img decoding=\"async\" width=\"644\" height=\"450\" title=\"image\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/0636.image_thumb_65241A39.png\" border=\"0\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>3. [Optional]: Replace the images in the Assets folder with the images from the sample project.<\/p>\n<p>4. Build and launch your project. You should see something like the following:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/8154.image_thumb_60AD9972.png\"><img decoding=\"async\" width=\"644\" height=\"404\" title=\"image\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/8154.image_thumb_60AD9972.png\" border=\"0\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/2671.image_thumb_6760A2F5.png\"><img decoding=\"async\" width=\"644\" height=\"404\" title=\"image\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/2671.image_thumb_6760A2F5.png\" border=\"0\" \/><\/a><\/p>\n<p>5. Now it&rsquo;s time to add the OData part of the application. Right-click on your project in the <strong>Solution Explorer<\/strong> and select <strong>Add Service Reference&hellip;<\/strong>:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/3660.image_thumb_5517DC33.png\"><img decoding=\"async\" width=\"381\" height=\"297\" title=\"image\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/3660.image_thumb_5517DC33.png\" border=\"0\" \/><\/a><\/p>\n<p>6. Enter the URL for the Netflix OData service in the <strong>Address<\/strong> bar and click <strong>Go<\/strong>. Set the <strong>Namespace<\/strong> of the service reference to <strong>Netflix<\/strong>:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/7077.image_thumb_14E1C2B9.png\"><img decoding=\"async\" width=\"596\" height=\"484\" title=\"image\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/7077.image_thumb_14E1C2B9.png\" border=\"0\" \/><\/a><\/p>\n<p><em>(Note: If you have not yet installed the tooling for consuming OData services in Windows Store apps, you will be prompted with a message such as the one above. You will need to download and install the tools referenced in the link to continue.)<\/em><\/p>\n<p>7. Replace the contents of <strong>SampleDataSource.cs<\/strong> from the <strong>DataModel<\/strong> folder. This data source provides sample data for bootstrapping Windows Store apps; we will replace it with a data source that gets real data from Netflix. This is the code that we will walk through in the <a href=\"http:\/\/blogs.msdn.com\/b\/astoriateam\/archive\/2012\/08\/23\/odata-101-building-our-first-odata-based-windows-store-app-part-2.aspx\">subsequent blog post<\/a>. For now, let&rsquo;s just copy and paste the code from <a href=\"https:\/\/gist.github.com\/3419288\" target=\"_blank\" rel=\"noopener\">this gist<\/a>.<\/p>\n<p>8. Add a <strong>Search Contract<\/strong> to the application. This will allows us to integrate with the <strong>Win+F<\/strong> experience. Name the Search Contract <strong>SearchResultsPage.xaml<\/strong>:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/3755.image_thumb_7B79BF7E.png\"><img decoding=\"async\" width=\"644\" height=\"446\" title=\"image\" style=\"border-width: 0px;padding-top: 0px;padding-right: 0px;padding-left: 0px\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/3755.image_thumb_7B79BF7E.png\" border=\"0\" \/><\/a><\/p>\n<p>9. Modify line 58 of <strong>SearchResultsPage.xaml.cs<\/strong> so that it doesn&rsquo;t embed quotes around the <strong>queryText<\/strong>:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/3362.image_thumb_6FE4023F.png\"><img decoding=\"async\" width=\"516\" height=\"62\" title=\"image\" style=\"border-width: 0px;padding-top: 0px;padding-right: 0px;padding-left: 0px\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/3362.image_thumb_6FE4023F.png\" border=\"0\" \/><\/a><\/p>\n<p>10. Insert the following two lines at line 81 of <strong>SearchResultsPage.xaml.cs<\/strong> to retrieve search results:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/0513.image_thumb_3D802EC0.png\"><img decoding=\"async\" width=\"644\" height=\"67\" title=\"image\" style=\"border-width: 0px;padding-top: 0px;padding-right: 0px;padding-left: 0px\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/0513.image_thumb_3D802EC0.png\" border=\"0\" \/><\/a><\/p>\n<p><em>(Note: <a href=\"https:\/\/gist.github.com\/3419288#file_search_results_page.xaml.cs\" target=\"_blank\" rel=\"noopener\">The gist<\/a> also includes the code for SearchResultsPage.xaml.cs if you would rather replace the entire contents of the file.)<\/em><\/p>\n<p>11. Launch the application and try it out. Note that it will take a few seconds to load the images upon application launch. Also, your first search attempt may not return any results. Obviously if this were a real-world application, you would want to deal with both of these issues.<\/p>\n<p>So that&rsquo;s it &ndash; we have now built an application that consumes and displays movies from the Netflix OData feed in the new Windows UI. In the <a href=\"http:\/\/blogs.msdn.com\/b\/astoriateam\/archive\/2012\/08\/23\/odata-101-building-our-first-odata-based-windows-store-app-part-2.aspx\">next blog post<\/a>, we&rsquo;ll dig into the code to see how it works.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Download the sample code In this OData 101 we will build a Windows Store app that consumes and displays movies from the Netflix OData feed. Specifically, we will focus on getting data, displaying it in the default grid layout, and enabling search functionality. Because there&rsquo;s a lot of details to talk about in this blog [&hellip;]<\/p>\n","protected":false},"author":512,"featured_media":3253,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[48,65,86],"class_list":["post-663","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-odata","tag-odata","tag-samples","tag-windows-8"],"acf":[],"blog_post_summary":"<p>Download the sample code In this OData 101 we will build a Windows Store app that consumes and displays movies from the Netflix OData feed. Specifically, we will focus on getting data, displaying it in the default grid layout, and enabling search functionality. Because there&rsquo;s a lot of details to talk about in this blog [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/users\/512"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/comments?post=663"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/663\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media\/3253"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media?parent=663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/categories?post=663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/tags?post=663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}