{"id":1494,"date":"2013-07-19T10:04:00","date_gmt":"2013-07-19T10:04:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2013\/07\/19\/writing-web-api-client-code-for-multiple-platforms-using-portable-libraries\/"},"modified":"2022-08-09T06:24:03","modified_gmt":"2022-08-09T13:24:03","slug":"writing-web-api-client-code-for-multiple-platforms-using-portable-libraries","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/writing-web-api-client-code-for-multiple-platforms-using-portable-libraries\/","title":{"rendered":"Writing Web API Client Code for Multiple Platforms Using Portable Libraries"},"content":{"rendered":"<p>The Microsoft ASP.NET Web API Client Libraries make it easy to write .NET clients that interact with RESTful HTTP services. Unfortunately, until recently the Web API client libraries did not support all platforms. Because of this limitation, developers had to maintain different code, depending on the target platform.<\/p>\n<p>The new release of Microsoft ASP.NET Web API Client Libraries now comes with support for building portable libraries that target .NET 4.5, Windows Store and Windows Phone 8 applications. This support is built on the recently released portable HttpClient and the portable library support in Json.NET. Developers can now build a single portable library that can be used to consume Web APIs from Windows Phone and Windows Store apps as well as from middle-tier logic running on .NET 4.5<\/p>\n<p>This blog post shows you how to create a reusable portable class library that consumes a sample HTTP service, and then how to use the library from a client application that targets multiple platforms.<\/p>\n<p><strong>Create the projects for different platforms<\/strong><\/p>\n<p>1. We will create three projects; a portable class library, which will actually use the Web API Client Libraries, a console application and a Windows Store app, which are the clients that will consume the portable library. <br \/>Create a new project named <strong>ContosoClient<\/strong> in C# with the Portable Class Library template. This is the common library that the other projects will use. The template is located under the Windows tab of the New Project dialog box:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/8306.clip_image002_thumb_18708751.png\"><img decoding=\"async\" title=\"clip_image002\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/8306.clip_image002_thumb_18708751.png\" alt=\"clip_image002\" width=\"462\" height=\"321\" border=\"0\" \/><\/a><\/p>\n<p>2. In the <strong>Add Portable Class Library<\/strong> dialog, select the <strong>.NET Framework 4.5<\/strong>, <strong>Windows Phone 8<\/strong>, and <strong>.NET for Windows Store apps<\/strong> target platforms. Depending on the target platforms that you select, different .NET profile will be used for this project.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/6175.clip_image004_thumb_1804545C.jpg\"><img decoding=\"async\" title=\"clip_image004\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/6175.clip_image004_thumb_1804545C.jpg\" alt=\"clip_image004\" width=\"322\" height=\"343\" border=\"0\" \/><\/a><\/p>\n<p><em>Note: This release of Microsoft ASP.NET Web API Client Libraries does not support Xbox 360, Silverlight, or Windows Phone 7.5 and lower. I won&rsquo;t show how to create a Windows Phone <a>8<\/a><\/em><a name=\"_msoanchor_1\" href=\"#_msocom_1\"><\/a>[MW1] <em> project in this article, but the ContosoClient portable library also supports Windows Phone 8. <\/em><\/p>\n<p>3. Create a Windows console app named <strong>ContosoConsole<\/strong>.<\/p>\n<p>4. Create a Windows Store app named <strong>ContosoStore <\/strong>with the <strong>Blank App (XAML)<\/strong> template as follows:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/0207.clip_image006_thumb_33A8E052.jpg\"><img decoding=\"async\" title=\"clip_image006\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/0207.clip_image006_thumb_33A8E052.jpg\" alt=\"clip_image006\" width=\"483\" height=\"335\" border=\"0\" \/><\/a><\/p>\n<p><strong>Configure the projects for the Web API Client Libraries <\/strong><\/p>\n<p>1. In Visual Studio, right-click the <strong>ContosoClient<\/strong> solution, and then select <strong>Manage NuGet Packages for solution<\/strong>. In the <strong>Manage NuGet Packages<\/strong> dialog, select <strong>Online<\/strong>-&gt;<strong>All<\/strong> in the left pane, select <strong>Include Prelease<\/strong>, and then search for &ldquo;<strong>Microsoft.AspNet.WebApi.Client<\/strong>&rdquo; as follows:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/2376.clip_image008_thumb_7372C6D7.jpg\"><img decoding=\"async\" title=\"clip_image008\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/2376.clip_image008_thumb_7372C6D7.jpg\" alt=\"clip_image008\" width=\"566\" height=\"229\" border=\"0\" \/><\/a><\/p>\n<p>2. Click the <strong>Install<\/strong> button to install the Web API Client Libraries in all three of the projects that we created.<\/p>\n<p><em>Note: Instead of having a single assembly set working for all the supported platforms, the Web API Client Libraries have two different sets of assemblies, depending on the target platforms. Because of this, you should install the package in all of the clients, although they do not directly use the libraries.<\/em><\/p>\n<p>3. In Visual Studio, add a reference to <strong>ContosoClient<\/strong> to both of <strong>ContosoConsole<\/strong> and <strong>ContosoStore<\/strong> as follows:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/6180.clip_image010_thumb_333CAD5D.jpg\"><img decoding=\"async\" title=\"clip_image010\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/6180.clip_image010_thumb_333CAD5D.jpg\" alt=\"clip_image010\" width=\"558\" height=\"248\" border=\"0\" \/><\/a><\/p>\n<p><strong>Update the projects to consume Contoso Recipe Service<\/strong><\/p>\n<p>1. In Visual Studio, go to <strong>ContosoClient<\/strong>, and then add the following code. It calls the Contoso Recipe sample service, and deserializes the JSON result into a list of <strong>RecipeDataItemDto<\/strong> objects. The recipe service returns much more data regarding each recipe, but in this sample we only serialize the title and ID, in order to simplify the code.<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7c60f0e9-d55c-491b-b2ca-3b8b3ccc39c2\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2.5em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #0000ff\">using<\/span><span style=\"background: #ffffff;color: #000000\"> System;<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #0000ff\">using<\/span><span style=\"background: #ffffff;color: #000000\"> System.Collections.Generic;<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">using<\/span><span style=\"background: #ffffff;color: #000000\"> System;<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #0000ff\">using<\/span><span style=\"background: #ffffff;color: #000000\"> System.Collections.Generic;<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">using<\/span><span style=\"background: #ffffff;color: #000000\"> System.Net.Http;<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #0000ff\">using<\/span><span style=\"background: #ffffff;color: #000000\"> System.Net.Http.Formatting;<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">using<\/span><span style=\"background: #ffffff;color: #000000\"> System.Net.Http.Headers;<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #0000ff\">using<\/span><span style=\"background: #ffffff;color: #000000\"> System.Threading.Tasks;<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">using<\/span><span style=\"background: #ffffff;color: #000000\"> Newtonsoft.Json;<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">namespace<\/span><span style=\"background: #ffffff;color: #000000\"> ContocoClient<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">class<\/span><span style=\"background: #ffffff;color: #2b91af\">RecipeDataAgent<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;<\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">async<\/span><span style=\"background: #ffffff;color: #2b91af\">Task<\/span><span style=\"background: #ffffff;color: #000000\">&lt;<\/span><span style=\"background: #ffffff;color: #2b91af\">IEnumerable<\/span><span style=\"background: #ffffff;color: #000000\">&lt;<\/span><span style=\"background: #ffffff;color: #2b91af\">RecipeDataItemDto<\/span><span style=\"background: #ffffff;color: #000000\">&gt;&gt; GetRecipeDataItemsAsync()<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">var<\/span><span style=\"background: #ffffff;color: #000000\"> client = <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> HttpClient();<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">client.BaseAddress = <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #2b91af\">Uri<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;http:\/\/contosorecipes8.blob.core.windows.net\/&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">var<\/span><span style=\"background: #ffffff;color: #000000\"> jsonTypeFormatter = <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> JsonMediaTypeFormatter();<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">jsonTypeFormatter.SupportedMediaTypes.Add(<\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> MediaTypeHeaderValue(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;application\/octet-stream&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">));<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">var<\/span><span style=\"background: #ffffff;color: #000000\"> response = <\/span><span style=\"background: #ffffff;color: #0000ff\">await<\/span><span style=\"background: #ffffff;color: #000000\"> client.GetAsync((<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;AzureRecipesRP&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">));<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return<\/span><span style=\"background: #ffffff;color: #0000ff\">await<\/span><span style=\"background: #ffffff;color: #000000\"> response.Content.ReadAsAsync&lt;<\/span><span style=\"background: #ffffff;color: #2b91af\">List<\/span><span style=\"background: #ffffff;color: #000000\">&lt;<\/span><span style=\"background: #ffffff;color: #2b91af\">RecipeDataItemDto<\/span><span style=\"background: #ffffff;color: #000000\">&gt;&gt;(<\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\">[] { jsonTypeFormatter }); ;<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">class<\/span><span style=\"background: #ffffff;color: #2b91af\">RecipeDataItemDto<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[JsonProperty(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;key&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> UniqueId<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{ <\/span><span style=\"background: #ffffff;color: #0000ff\">get<\/span><span style=\"background: #ffffff;color: #000000\">; <\/span><span style=\"background: #ffffff;color: #0000ff\">set<\/span><span style=\"background: #ffffff;color: #000000\">; }<\/span><\/li>\n<li>&nbsp;<\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> Title<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{ <\/span><span style=\"background: #ffffff;color: #0000ff\">get<\/span><span style=\"background: #ffffff;color: #000000\">; <\/span><span style=\"background: #ffffff;color: #0000ff\">set<\/span><span style=\"background: #ffffff;color: #000000\">; }<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<pre>&nbsp;<\/pre>\n<p>2. In Visual Studio, go to <strong>ContosoClient<\/strong> and add the following code to <strong>Program.cs<\/strong>.<\/p>\n<p>using ContocoClient;<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:05c090b7-54cb-47a6-b0fb-8e68f0204f27\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2.5em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #0000ff\">namespace<\/span><span style=\"background: #ffffff;color: #000000\"> ContosoConsole<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">class<\/span><span style=\"background: #ffffff;color: #2b91af\">Program<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">static<\/span><span style=\"background: #ffffff;color: #0000ff\">void<\/span><span style=\"background: #ffffff;color: #000000\"> Main(<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\">[] args)<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">CallRecipeServiceAsync().Wait();<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li>&nbsp;<\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">static<\/span><span style=\"background: #ffffff;color: #0000ff\">async<\/span><span style=\"background: #ffffff;color: #000000\"> Task CallRecipeServiceAsync()<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">var<\/span><span style=\"background: #ffffff;color: #000000\"> recipes = <\/span><span style=\"background: #ffffff;color: #0000ff\">await<\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> RecipeDataAgent().GetRecipeDataItemsAsync();<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">foreach<\/span><span style=\"background: #ffffff;color: #000000\"> (<\/span><span style=\"background: #ffffff;color: #0000ff\">var<\/span><span style=\"background: #ffffff;color: #000000\"> receipe <\/span><span style=\"background: #ffffff;color: #0000ff\">in<\/span><span style=\"background: #ffffff;color: #000000\"> recipes)<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">Console.WriteLine(receipe.Title);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p><a>3. Run the console application by pressing Ctrl+F5. The application will show the title of the all the recipes that the service returns<\/a>:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/2783.clip_image012_thumb_07F81656.png\"><img decoding=\"async\" title=\"clip_image012\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/2783.clip_image012_thumb_07F81656.png\" alt=\"clip_image012\" width=\"628\" height=\"324\" border=\"0\" \/><\/a><\/p>\n<p>4. In Visual Studio, go to <strong>ContosoStore<\/strong> and add the following code into the <strong>&lt;Page&gt;<\/strong> element in <strong>MainPage.xaml<\/strong>.<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0ff8be2e-40a4-4642-a9ab-90d8e46d5d50\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #0000ff\">&lt;<\/span><span style=\"background: #ffffff;color: #a31515\">Grid<\/span><span style=\"background: #ffffff;color: #ff0000\">Background<\/span><span style=\"background: #ffffff;color: #0000ff\">=<\/span><span style=\"background: #ffffff;color: #000000\">&#8220;{<\/span><span style=\"background: #ffffff;color: #0000ff\">StaticResource ApplicationPageBackgroundThemeBrush}<\/span><span style=\"background: #ffffff;color: #000000\">&#8220;<\/span><span style=\"background: #ffffff;color: #0000ff\">&gt;<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">&lt;<\/span><span style=\"background: #ffffff;color: #a31515\">ListView<\/span><span style=\"background: #ffffff;color: #ff0000\">x:Name<\/span><span style=\"background: #ffffff;color: #0000ff\">=<\/span><span style=\"background: #ffffff;color: #000000\">&#8220;<\/span><span style=\"background: #ffffff;color: #0000ff\">itemListView<\/span><span style=\"background: #ffffff;color: #000000\">&#8220;<\/span><span style=\"background: #ffffff;color: #0000ff\">\/&gt;<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">&lt;\/<\/span><span style=\"background: #ffffff;color: #a31515\">Grid<\/span><span style=\"background: #ffffff;color: #0000ff\">&gt;<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p>5. In <strong>MainPage.xaml.cs<\/strong>, add the following method to the <strong>MainPage<\/strong> class.<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:463dc1f0-a41f-438e-b8d7-46b3510c961a\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #000000\"> async <\/span><span style=\"background: #ffffff;color: #0000ff\">void<\/span><span style=\"background: #ffffff;color: #000000\"> UpdateListView()<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">var recipes = await <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> RecipeDataAgent().GetRecipeDataItemsAsync();<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">foreach<\/span><span style=\"background: #ffffff;color: #000000\"> (var receipe <\/span><span style=\"background: #ffffff;color: #0000ff\">in<\/span><span style=\"background: #ffffff;color: #000000\"> recipes)<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">itemListView.Items.Add(receipe.Title);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p>6. Call the UpdateListView method from the <strong>NavigatedTo<\/strong> method.<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f5519b0c-ee22-48fc-8c11-935b7d220df0\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #0000ff\">protected<\/span><span style=\"background: #ffffff;color: #0000ff\">override<\/span><span style=\"background: #ffffff;color: #0000ff\">void<\/span><span style=\"background: #ffffff;color: #000000\"> OnNavigatedTo(NavigationEventArgs e)<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">UpdateListView();<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p><a>7. Run the Windows Store app by pressing Ctrl+F5. The app will show the titles in the list view.<\/a><a name=\"_msoanchor_2\" href=\"#_msocom_2\"><\/a>[DR2]<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/4442.clip_image014_thumb_27A6F01E.png\"><img decoding=\"async\" title=\"clip_image014\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/4442.clip_image014_thumb_27A6F01E.png\" alt=\"clip_image014\" width=\"628\" height=\"424\" border=\"0\" \/><\/a><\/p>\n<p><strong>Summary<\/strong><\/p>\n<p>The Web API Client Libraries make it easy to write Web API clients, but until now you had to maintain different source code for each platform using platform-specific APIs. With this release you can now write portable Web API client code that targets .NET 4.5, Windows Store apps and Windows Phone 8 apps. Enjoy!<\/p>\n<hr align=\"left\" size=\"1\" width=\"33%\" \/>\n","protected":false},"excerpt":{"rendered":"<p>The Microsoft ASP.NET Web API Client Libraries make it easy to write .NET clients that interact with RESTful HTTP services. Unfortunately, until recently the Web API client libraries did not support all platforms. Because of this limitation, developers had to maintain different code, depending on the target platform. The new release of Microsoft ASP.NET Web [&hellip;]<\/p>\n","protected":false},"author":428,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[4,31,7347,34,46],"class_list":["post-1494","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","tag-net","tag-asp-net","tag-asp-net-4","tag-asp-net-web-api","tag-c"],"acf":[],"blog_post_summary":"<p>The Microsoft ASP.NET Web API Client Libraries make it easy to write .NET clients that interact with RESTful HTTP services. Unfortunately, until recently the Web API client libraries did not support all platforms. Because of this limitation, developers had to maintain different code, depending on the target platform. The new release of Microsoft ASP.NET Web [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/1494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/428"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=1494"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/1494\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=1494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=1494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=1494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}