<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>ASP.NET Web Api</title>
        <link>http://blogs.ugidotnet.org/pietrolibroblog/category/ASP.NET Web Api.aspx</link>
        <description>ASP.NET Web Api</description>
        <language>it-IT</language>
        <copyright>Pietro Libro</copyright>
        <managingEditor>pietro.libro@libero.it</managingEditor>
        <generator>Subtext Version 2.6.0.0</generator>
        <item>
            <title>Asp.Net 5, MVC 6 e Web Api</title>
            <link>http://blogs.ugidotnet.org/pietrolibroblog/archive/2014/11/23/asp.net-5-mvc-6-e-web-api.aspx</link>
            <description>&lt;p&gt;E’ qualche mese che non scrivo nulla sul blog, ma gli studi, come la vita, sono andata avanti. Ora eccoci qui a fare qualche test con le nuove versioni delle ultime tecnologie\framework web del mondo Microsoft, che ci regala ogni giorno qualcosa di tecnlogicamente fantastico…alla faccia dei soliti criticoni &lt;img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/wlEmoticon-smile_2.png" /&gt;. Torniamo con i piedi per terra e proviamo ad utilizzare le Web Api in un progetto MVC 6 (attualmente in versione beta, ASP.NET 5 fonde i framework MCV e Web Api). Apriamo il nostro VS 2015 preview (scaricabile nella versione ultimate a questo indirizzo: ) e creiamo un nuovo progetto “ASP.NET Web Application”:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_4.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_thumb_1.png" width="244" height="170" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Poi selezioniamo il template &lt;em&gt;ASP.NET 5 Empty&lt;/em&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_8.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_thumb_3.png" width="244" height="183" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Attendiamo qualche secondo che Visual Studio crei l’alberatura della soluzione con tutti i relativi file:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_10.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_thumb_4.png" width="244" height="195" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Notiamo due file in formato “.json”, &lt;em&gt;global.json&lt;/em&gt; e &lt;em&gt;project.json&lt;/em&gt;, che possiamo editare rispettivamente per i &lt;em&gt;settings&lt;/em&gt; e per le &lt;em&gt;references&lt;/em&gt; a livello globale (solution) o di singolo progetto. La classe &lt;em&gt;Startup.cs&lt;/em&gt; ed in particolare il metodo &lt;em&gt;Configure(…)&lt;/em&gt; definisce l’entry point della pipeline di ASP.NET, ed è qui che andremo ad aggiungere il codice necessario all’esecuzione dell’applicazione. Prima, apriamo il file &lt;em&gt;project.json&lt;/em&gt;, e nella sezione &lt;em&gt;dependencies &lt;/em&gt;aggiungiamo la riga seguente:&lt;/p&gt;  &lt;div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:31fa74eb-3a4e-4854-8d55-ea86cd323d50" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt;&lt;pre class="brush: csharp; gutter: true; first-line: 1; tab-size: 4;  toolbar: false;  width: 422px; height: 22px;" style=" width: 422px; height: 22px;overflow: auto;"&gt;"Microsoft.AspNet.Mvc": "6.0.0-beta1"&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Notare come l’editor sia completo di &lt;em&gt;IntelliSense &lt;/em&gt;che ci permette di scegliere dinamicamente package e versione (tra quelle disponibili):&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_12.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_thumb_5.png" width="244" height="116" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inizializziamo MVC nella classe &lt;em&gt;Startup.cs&lt;/em&gt;, aggiungendo il metodo &lt;em&gt;ConfigureServices&lt;/em&gt;:&lt;/p&gt;

&lt;div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:400b0b3f-550e-45e9-a8dc-b48fde71e3c8" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt;&lt;pre style=" width: 574px; height: 79px;background-color:White;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #008080;"&gt;1&lt;/span&gt; &lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;void&lt;/span&gt;&lt;span style="color: #000000;"&gt; ConfigureServices(IServiceCollection services) 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;2&lt;/span&gt; &lt;span style="color: #000000;"&gt;{ 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;3&lt;/span&gt; &lt;span style="color: #000000;"&gt;    services.AddMvc(); 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;4&lt;/span&gt; &lt;span style="color: #000000;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;il quale aggiunge tutte le dipendenze di cui MVC 6 ha bisogno. Utilizziamo il metodo d’estensione &lt;em&gt;UseMvc &lt;/em&gt;nel metodo &lt;em&gt;Configure:&lt;/em&gt;&lt;/p&gt;

&lt;div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:133d9ce7-f372-4822-b58e-2673ebd60673" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt;&lt;pre style=" width: 574px; height: 79px;background-color:White;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #008080;"&gt;1&lt;/span&gt; &lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;void&lt;/span&gt;&lt;span style="color: #000000;"&gt; Configure(IApplicationBuilder app) 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;2&lt;/span&gt; &lt;span style="color: #000000;"&gt;{            
&lt;/span&gt;&lt;span style="color: #008080;"&gt;3&lt;/span&gt; &lt;span style="color: #000000;"&gt;    app.UseMvc(); 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;4&lt;/span&gt; &lt;span style="color: #000000;"&gt;} &lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Aggiungiamo una classe &lt;em&gt;ItemsController &lt;/em&gt;(“Web Api Controller Class”) nella classica cartella di progetto &lt;em&gt;Controllers&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_14.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_thumb_6.png" width="244" height="170" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:52bc49db-9ffe-4a96-aece-068adc238076" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt;&lt;pre style=" width: 782px; height: 226px;background-color:White;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #008080;"&gt; 1&lt;/span&gt; &lt;span style="color: #000000;"&gt;[Route(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;api/[controller]&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;)] 
&lt;/span&gt;&lt;span style="color: #008080;"&gt; 2&lt;/span&gt; &lt;span style="color: #000000;" /&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;class&lt;/span&gt;&lt;span style="color: #000000;"&gt; ItemsController : Controller 
&lt;/span&gt;&lt;span style="color: #008080;"&gt; 3&lt;/span&gt; &lt;span style="color: #000000;"&gt;{ 
&lt;/span&gt;&lt;span style="color: #008080;"&gt; 4&lt;/span&gt; &lt;span style="color: #000000;"&gt;    &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; GET: api/values &lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #008080;"&gt; 5&lt;/span&gt; &lt;span style="color: #008000;" /&gt;&lt;span style="color: #000000;"&gt;    [HttpGet] 
&lt;/span&gt;&lt;span style="color: #008080;"&gt; 6&lt;/span&gt; &lt;span style="color: #000000;"&gt;    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; IEnumerable&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Item&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; Get() 
&lt;/span&gt;&lt;span style="color: #008080;"&gt; 7&lt;/span&gt; &lt;span style="color: #000000;"&gt;    { 
&lt;/span&gt;&lt;span style="color: #008080;"&gt; 8&lt;/span&gt; &lt;span style="color: #000000;"&gt;        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; List&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Item&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;( 
&lt;/span&gt;&lt;span style="color: #008080;"&gt; 9&lt;/span&gt; &lt;span style="color: #000000;"&gt;            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; Item[]{ 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;10&lt;/span&gt; &lt;span style="color: #000000;"&gt;                &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; Item() { Code&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Item#1&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, Description&lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Item_Description#1&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt; }, 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;11&lt;/span&gt; &lt;span style="color: #000000;"&gt;                &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; Item() { Code &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Item2&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, Description &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Item_Description#2&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;} }); 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;12&lt;/span&gt; &lt;span style="color: #000000;"&gt;    } 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;13&lt;/span&gt; &lt;span style="color: #000000;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Poi aggiungiamo la classe &lt;em&gt;Item&lt;/em&gt;:&lt;/p&gt;

&lt;div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:8bef8468-3a84-4e1b-b9c2-e6cdc95b167b" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt;&lt;pre style=" width: 467px; height: 92px;background-color:White;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #008080;"&gt;1&lt;/span&gt; &lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;class&lt;/span&gt;&lt;span style="color: #000000;"&gt; Item 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;2&lt;/span&gt; &lt;span style="color: #000000;"&gt;{ 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;3&lt;/span&gt; &lt;span style="color: #000000;"&gt;    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; Code { &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;get&lt;/span&gt;&lt;span style="color: #000000;"&gt;; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;set&lt;/span&gt;&lt;span style="color: #000000;"&gt;; } 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;4&lt;/span&gt; &lt;span style="color: #000000;"&gt;    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; Description { &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;get&lt;/span&gt;&lt;span style="color: #000000;"&gt;; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;set&lt;/span&gt;&lt;span style="color: #000000;"&gt;; } 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;5&lt;/span&gt; &lt;span style="color: #000000;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Avviamo il progetto ed invochiamo via browser il servizio:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_16.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_thumb_7.png" width="244" height="49" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Il servizio dovrebbe restituire il seguente json :&lt;/p&gt;

&lt;div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:6292c1a2-9f59-4ab1-acc2-227a4a001d03" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt;&lt;pre style=" width: 640px; height: 51px;background-color:White;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #008080;"&gt;1&lt;/span&gt; &lt;span style="color: #000000;"&gt;[{&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Code&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;:&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Item#1&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;,&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Description&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;:&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Item_Description#1&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;}
&lt;/span&gt;&lt;span style="color: #008080;"&gt;2&lt;/span&gt; &lt;span style="color: #000000;"&gt;,{&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Code&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;:&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Item2&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;,&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Description&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;:&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Item_Description#2&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;}]&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Notiamo come la classe &lt;em&gt;ItemsController&lt;/em&gt; a differenza delle versioni precedenti, non derivi piu’ dalla classe &lt;em&gt;ApiController&lt;/em&gt;, ma direttamente da &lt;em&gt;Controller&lt;/em&gt;. Se proviamo ad utilizzare uno strumento come &lt;a href="http://www.telerik.com/fiddler" target="_blank"&gt;Fiddler&lt;/a&gt; per analizzare le &lt;em&gt;request &lt;/em&gt;e le &lt;em&gt;response &lt;/em&gt;delle nostre Api, possiamo scoprire qualcosa di interessante, se ad esempio, modifichiamo la nostra Web Api in modo da tornare &lt;em&gt;null, c&lt;/em&gt;on l’attuale versione di ASP.NET Web Api otterremmo:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_18.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_thumb_8.png" width="244" height="56" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ovvero una &lt;em&gt;response &lt;/em&gt;con status 200 e corpo del messaggio vuoto, con la versione MVC 6 invece:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_20.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/image_thumb_9.png" width="244" height="31" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Una &lt;em&gt;response &lt;/em&gt;con status 204 (No Content), che logicamente parlando IMHO è piu’ corretta (la risposta è OK, ma il contenuto del body è vuoto). Ulteriori dettagli sui &lt;em&gt;Formatters&lt;/em&gt; in MVC6 possono essere trovati in questo &lt;a href="http://www.strathweb.com/2014/11/formatters-asp-net-mvc-6/" target="_blank"&gt;post&lt;/a&gt; di Filip W. Per ritornare ad avere un comportamento &lt;em&gt;Old Style&lt;/em&gt; è sufficiente agire a livello di configurazione, in &lt;em&gt;ConfigureServices&lt;/em&gt;:&lt;/p&gt;

&lt;div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:9cef9395-8948-42b0-8de5-e233c45d8634" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt;&lt;pre style=" width: 781px; height: 92px;background-color:White;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #008080;"&gt;1&lt;/span&gt; &lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;void&lt;/span&gt;&lt;span style="color: #000000;"&gt; ConfigureServices(IServiceCollection services) 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;2&lt;/span&gt; &lt;span style="color: #000000;"&gt;{ 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;3&lt;/span&gt; &lt;span style="color: #000000;"&gt;    services.AddMvc().Configure&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;MvcOptions&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(o &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; o.OutputFormatters 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;4&lt;/span&gt; &lt;span style="color: #000000;"&gt;    .RemoveAll(f &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; f.Instance.GetType() &lt;/span&gt;&lt;span style="color: #000000;"&gt;==&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;typeof&lt;/span&gt;&lt;span style="color: #000000;"&gt;(HttpNoContentOutputFormatter))); 
&lt;/span&gt;&lt;span style="color: #008080;"&gt;5&lt;/span&gt; &lt;span style="color: #000000;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Ovviamente di novità ci sono e tante, ma almeno sappiamo da dove iniziare &lt;img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/AspNet-5-MVC-6-Web-Api_112BD/wlEmoticon-smile_2.png" /&gt; .

  &lt;/p&gt;&lt;img src="http://blogs.ugidotnet.org/pietrolibroblog/aggbug/101903.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Pietro Libro</dc:creator>
            <guid>http://blogs.ugidotnet.org/pietrolibroblog/archive/2014/11/23/asp.net-5-mvc-6-e-web-api.aspx</guid>
            <pubDate>Sun, 23 Nov 2014 10:17:55 GMT</pubDate>
            <comments>http://blogs.ugidotnet.org/pietrolibroblog/archive/2014/11/23/asp.net-5-mvc-6-e-web-api.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.ugidotnet.org/pietrolibroblog/comments/commentRss/101903.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.ugidotnet.org/pietrolibroblog/services/trackbacks/101903.aspx</trackback:ping>
        </item>
        <item>
            <title>JSON.Merge</title>
            <link>http://blogs.ugidotnet.org/pietrolibroblog/archive/2014/08/29/json.merge.aspx</link>
            <description>&lt;p&gt;Un’interessante novità introdotta con la versione 6.0 release 4 di Json.NET è la possibilità di eseguire il &lt;em&gt;Merge&lt;/em&gt; (utilizzando 4 possibili “variazioni”) di oggetti &lt;em&gt;JObject&lt;/em&gt; e &lt;em&gt;Jarray&lt;/em&gt;. Un rapido esempio, tramite Web Api:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;[HttpPost]        
public void JsonStringPost([FromBody]string value)
{
    JObject jCar = JObject.Parse(value);
    JObject jOptional = JObject.Parse(@"{Optionals :['Air Conditioned','Smoker'] }");

    jCar.Merge(jOptional, new JsonMergeSettings() { MergeArrayHandling = MergeArrayHandling.Union });

    string jsonFormat = jCar.ToString();
    Car mergedCar =  jCar.ToObject&amp;lt;Car&amp;gt;(); 
}&lt;/pre&gt;

&lt;p&gt;Dove &lt;em&gt;l’Action&lt;/em&gt; “JsonStringPost” accetta una stringa tipo:&lt;/p&gt;

&lt;p&gt;"{ 'Brand': 'Ferrari','Model': 'f450 Modena','Optionals': [] }"&lt;/p&gt;

&lt;p&gt;Utilizzando, ad esempio il &lt;em&gt;Composer&lt;/em&gt; di strumenti come &lt;a href="http://www.telerik.com/fiddler" target="_blank"&gt;Fiddler2&lt;/a&gt; possiamo invocare il servizio:&lt;/p&gt;
&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/JSON.Merge_A854/image_5.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/JSON.Merge_A854/image_thumb_1.png" width="244" height="238" /&gt;&lt;/a&gt; 

&lt;p&gt;Per ottenere una nuova istanza di &lt;em&gt;Car&lt;/em&gt; con tutti gli &lt;em&gt;Optionals&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/JSON.Merge_A854/image_7.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/JSON.Merge_A854/image_thumb_2.png" width="244" height="74" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Se il nostro servizio accetta direttamente un’istanza di oggetto invece di una stringa in formato JSON, il nostro codice cambia leggermente, come di seguito:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;[HttpPost]
public void JsonObjectPost([FromBody] Car carByPost)
{
    JObject jCar = JObject.FromObject(carByPost);

    JObject jOptional = JObject.Parse(@"{Optionals :['Air Conditioned','Smoker'] }");
    jCar.Merge(jOptional, new JsonMergeSettings() { MergeArrayHandling = MergeArrayHandling.Union });

    string jsonFormat = jCar.ToString();
    Car mergedCar = jCar.ToObject&lt;car&gt;();
}&lt;/car&gt;&lt;/pre&gt;

&lt;p&gt;Dove utilizziamo il metodo &lt;em&gt;FromObject&lt;/em&gt; della classe &lt;em&gt;JObject&lt;/em&gt; invece di &lt;em&gt;Parse. &lt;/em&gt;Utilizzando Fiddler, passando come &lt;em&gt;Body&lt;/em&gt; del messaggio la stringa (senza i doppi apici ad inizio e fine stringa)&lt;/p&gt;

&lt;p&gt;{ 'Brand': 'Ferrari','Model': 'f450 Modena','Optionals': [] }&lt;/p&gt;

&lt;p&gt;Otteniamo (ovviamente) lo stesso risultato dell’invocazione precedente. E’ possibile modificare il comportamento di “Merge” utilizzando l’enumerazione &lt;em&gt;MergeArrayHandling. &lt;/em&gt;La classe &lt;em&gt;Car &lt;/em&gt;(C#) è descritta nell’esempio, è la seguente:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public class Car
{
    public string Brand { get; set; }
    public string Model { get; set; }
    public string[] Optionals { get; set; }
}&lt;/pre&gt;

&lt;p&gt;La lista completa delle &lt;em&gt;features&lt;/em&gt; aggiunte nel rilascio della versione 6.0 release 4 è disponibile &lt;a href="http://james.newtonking.com/archive/2014/08/04/json-net-6-0-release-4-json-merge-dependency-injection" target="_blank"&gt;qui&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.ugidotnet.org/pietrolibroblog/aggbug/101880.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Pietro Libro</dc:creator>
            <guid>http://blogs.ugidotnet.org/pietrolibroblog/archive/2014/08/29/json.merge.aspx</guid>
            <pubDate>Fri, 29 Aug 2014 13:30:00 GMT</pubDate>
            <comments>http://blogs.ugidotnet.org/pietrolibroblog/archive/2014/08/29/json.merge.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.ugidotnet.org/pietrolibroblog/comments/commentRss/101880.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.ugidotnet.org/pietrolibroblog/services/trackbacks/101880.aspx</trackback:ping>
        </item>
        <item>
            <title>Request Batching in Web Api 2</title>
            <link>http://blogs.ugidotnet.org/pietrolibroblog/archive/2013/12/23/request-batching-in-web-api-2.aspx</link>
            <description>&lt;p&gt;Una funzionalità molto interessante introdotta con ASP.NET Web API 2 OData è il supporto “Batching”, ovvero la possibilità di “impacchettare” in una singola richiesta HTTP piu’ richieste Web API (&lt;em&gt;action&lt;/em&gt;) e ricevere in un’unica risposta HTTP i risultati ottenuti dalle singole invocazioni delle Web API. Questa funzionalità è molto interessante in quanto ci permette di minimizzare il numero di richieste\risposte tra client e server, riducendo il traffico di rete (pensiamo al Cloud…).  &lt;/p&gt; &lt;p&gt;Per abilitare &lt;em&gt;Server Side&lt;/em&gt; questa funzionalità è necessario esporre tramite registrazione, un &lt;em&gt;HTTP batch endpoint&lt;/em&gt; utilizzando il metodo &lt;em&gt;MapHttpBatchRoute&lt;/em&gt; esposto dall’instanza &lt;em&gt;Routes&lt;/em&gt; della classe &lt;em&gt;HttpRouteCollection&lt;/em&gt;:&lt;/p&gt;&lt;pre class="csharpcode"&gt;config.Routes.MapHttpBatchRoute(
        routeName: &lt;span class="str"&gt;"BatchApi"&lt;/span&gt;,
        routeTemplate: &lt;span class="str"&gt;"api/batch"&lt;/span&gt;,
        batchHandler: &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Web.Http.Batch.DefaultHttpBatchHandler(GlobalConfiguration.DefaultServer));&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Il codice del Controller Web Api è relativamente semplice (è in allegato) ed è stato utilizzato come DEMO per la mia sessione durante l’ultimo l’evento organizzato da &lt;a href="http://www.domusdotnet.org/" target="_blank"&gt;DomusDotNet&lt;/a&gt;. A questo punto la palla passa &lt;em&gt;Client Side&lt;/em&gt;, dove tramite un’unica chiamata HTTP vogliamo ottenere l’elenco di tutte le entità &lt;em&gt;Car&lt;/em&gt; serializzate, l’inserimento di una nuova entità &lt;em&gt;Car&lt;/em&gt; e la modifica del valore di una proprietà di un’entità precedentemente recuperata.&lt;/p&gt;
&lt;p&gt;Iniziamo con il recuperare l’entità &lt;em&gt;Car&lt;/em&gt; con Id=1&lt;/p&gt;&lt;pre class="csharpcode"&gt;HttpClient client = &lt;span class="kwrd"&gt;new&lt;/span&gt; HttpClient();
&lt;span class="kwrd"&gt;string&lt;/span&gt; response = await client.GetStringAsync(&lt;span class="str"&gt;"http://localhost:31613/Api/Cars/1"&lt;/span&gt;);

Car car = (Newtonsoft.Json.JsonConvert.DeserializeObject(response)
    &lt;span class="kwrd"&gt;as&lt;/span&gt; Newtonsoft.Json.Linq.JObject).ToObject&amp;lt;Car&amp;gt;();&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Poi un &lt;em&gt;HttpRequestMessage&lt;/em&gt; per ottenere (GET) l’elenco di tutte le entità:&lt;/p&gt;&lt;pre class="csharpcode"&gt;HttpRequestMessage getCars = &lt;span class="kwrd"&gt;new&lt;/span&gt; HttpRequestMessage(HttpMethod.Get, &lt;span class="str"&gt;&lt;a href="http://localhost:31613/Api/Cars"&gt;http://localhost:31613/Api/Cars&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;&lt;pre class="csharpcode"&gt; &lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Un altro &lt;em&gt;HttpRequestMessage&lt;/em&gt; per aggiungere (POST) una nuova entità:&lt;/p&gt;&lt;pre class="csharpcode"&gt;JsonMediaTypeFormatter formatter = &lt;span class="kwrd"&gt;new&lt;/span&gt; JsonMediaTypeFormatter();
HttpRequestMessage postCar = &lt;span class="kwrd"&gt;new&lt;/span&gt; HttpRequestMessage(HttpMethod.Post, &lt;span class="str"&gt;"http://localhost:31613/Api/Cars"&lt;/span&gt;);
postCar.Content = &lt;span class="kwrd"&gt;new&lt;/span&gt; ObjectContent&amp;lt;Car&amp;gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; Car()
{
    Brand_Id = 1,
    DailyRent = 50.0f,
    EngineSize = &lt;span class="str"&gt;"2500"&lt;/span&gt;,
    Model = &lt;span class="str"&gt;"GTV"&lt;/span&gt;,
    Note = &lt;span class="str"&gt;"---"&lt;/span&gt;
},formatter);&lt;/pre&gt;&lt;pre class="csharpcode"&gt; &lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Ed infine un &lt;em&gt;HttpRequestMessage&lt;/em&gt; per aggiornare (PUT) l’entità &lt;em&gt;Car&lt;/em&gt; precedentemente recuperata:&lt;/p&gt;&lt;pre class="csharpcode"&gt;car.Note += &lt;span class="str"&gt;" BATCH"&lt;/span&gt;;
HttpRequestMessage putCar = &lt;span class="kwrd"&gt;new&lt;/span&gt; HttpRequestMessage(HttpMethod.Put,
    &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"http://localhost:31613/Api/Cars?id={0}"&lt;/span&gt;, car.Id));
putCar.Content = &lt;span class="kwrd"&gt;new&lt;/span&gt; ObjectContent&amp;lt;dynamic&amp;gt;(car, formatter);&lt;/pre&gt;&lt;pre class="csharpcode"&gt; &lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;a questo punto, dobbiamo “impacchettare” le singole richieste in un’unica richiesta HTTP, utilizzanto un’istanza di &lt;em&gt;MultiPartContent&lt;/em&gt;:&lt;/p&gt;&lt;pre class="csharpcode"&gt;HttpMessageContent getCarsContent = &lt;span class="kwrd"&gt;new&lt;/span&gt; HttpMessageContent(getCars);
HttpMessageContent postCarContent = &lt;span class="kwrd"&gt;new&lt;/span&gt; HttpMessageContent(postCar);
HttpMessageContent putCarContent = &lt;span class="kwrd"&gt;new&lt;/span&gt; HttpMessageContent(putCar);

MultipartContent multiPartContent = &lt;span class="kwrd"&gt;new&lt;/span&gt; MultipartContent(&lt;span class="str"&gt;"mixed"&lt;/span&gt;, &lt;span class="str"&gt;"batch_"&lt;/span&gt; + Guid.NewGuid().ToString());
multiPartContent.Add(getCarsContent);
multiPartContent.Add(postCarContent);
multiPartContent.Add(putCarContent);

HttpRequestMessage batchRequest = &lt;span class="kwrd"&gt;new&lt;/span&gt; HttpRequestMessage(HttpMethod.Post, &lt;span class="str"&gt;"http://localhost:31613/api/batch"&lt;/span&gt;);
batchRequest.Content = multiPartContent;&lt;/pre&gt;&lt;pre class="csharpcode"&gt; &lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Non ci resta che effettuare la richiesta al &lt;em&gt;Server&lt;/em&gt;:&lt;/p&gt;&lt;pre class="csharpcode"&gt;HttpResponseMessage multipartResponse = await client.SendAsync(batchRequest);
MultipartMemoryStreamProvider responseContents = await multipartResponse.Content.ReadAsMultipartAsync();&lt;/pre&gt;&lt;pre class="csharpcode"&gt; &lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;e recuperare le singole risposte:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;////Status Code: 200, Ok.&lt;/span&gt;
HttpResponseMessage getResponse = await responseContents.Contents[0].ReadAsHttpResponseMessageAsync();
&lt;span class="rem"&gt;////Status Code: 201, Created.&lt;/span&gt;
HttpResponseMessage postResponse = await responseContents.Contents[1].ReadAsHttpResponseMessageAsync();
&lt;span class="rem"&gt;////Status Code:204, Not Content.&lt;/span&gt;
HttpResponseMessage putResponse = await responseContents.Contents[2].ReadAsHttpResponseMessageAsync();&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Normalmente le singole richieste contenute all’interno di un “batch” sono eseguite sequenzialmente, di conseguenza in questo caso, la richiesta di POST partirebbe subito dopo quella di GET ed immediatamente prima di quella di PUT. Se l’ordine di esecuzione non è importante, possiamo eseguire le richieste in modo asincrono impostando la proprietà &lt;em&gt;ExecutionOrder &lt;/em&gt;a &lt;em&gt;BatchExecutionOrder.NonSequential:&lt;/em&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;config.Routes.MapHttpBatchRoute(
    routeName: &lt;span class="str"&gt;"BatchApi"&lt;/span&gt;,
    routeTemplate: &lt;span class="str"&gt;"api/batch"&lt;/span&gt;,
    batchHandler: &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Web.Http.Batch.DefaultHttpBatchHandler(GlobalConfiguration.DefaultServer)
    {
        ExecutionOrder = System.Web.Http.Batch.BatchExecutionOrder.NonSequential
    });&lt;/pre&gt;&lt;pre class="csharpcode"&gt; &lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;div id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:7b2b768f-9337-4757-86e0-c75f6442084c" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt;&lt;p&gt;Attach &lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Batch-Requestes-in-Web-Api-2_86F2/CarsController.cs" target="_blank"&gt;Cars Controller Code&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;&lt;img src="http://blogs.ugidotnet.org/pietrolibroblog/aggbug/101749.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Pietro Libro</dc:creator>
            <guid>http://blogs.ugidotnet.org/pietrolibroblog/archive/2013/12/23/request-batching-in-web-api-2.aspx</guid>
            <pubDate>Mon, 23 Dec 2013 12:49:00 GMT</pubDate>
            <comments>http://blogs.ugidotnet.org/pietrolibroblog/archive/2013/12/23/request-batching-in-web-api-2.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.ugidotnet.org/pietrolibroblog/comments/commentRss/101749.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.ugidotnet.org/pietrolibroblog/services/trackbacks/101749.aspx</trackback:ping>
        </item>
        <item>
            <title>Web Api e Debug su Azure</title>
            <link>http://blogs.ugidotnet.org/pietrolibroblog/archive/2013/11/19/web-api-e-debug-su-azure.aspx</link>
            <description>&lt;p&gt;Se abbiamo la necessità di debuggare le nostre Web Api pubblicate su Azure, i passi da seguire sono veramente pochi e semplici:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Download ed installazione di Azure SDK 2.2 &lt;/li&gt;    &lt;li&gt;Aprire la &lt;em&gt;Solution &lt;/em&gt;contenente&lt;em&gt; &lt;/em&gt;il progetto Web con la definizione delle Web API &lt;/li&gt;    &lt;li&gt;Connettersi a &lt;em&gt;Windows Azure&lt;/em&gt; tramite l’apposito link in &lt;em&gt;Server Explorer&lt;/em&gt;:       &lt;br /&gt;      &lt;br /&gt;      &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Web-Api-Debug-su-Azure_783C/image_2.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Web-Api-Debug-su-Azure_783C/image_thumb.png" width="244" height="156" /&gt;&lt;/a&gt;&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;Pubblicare il progetto (in Debug):      &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Web-Api-Debug-su-Azure_783C/image_8.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Web-Api-Debug-su-Azure_783C/image_thumb_3.png" width="244" height="92" /&gt;&lt;/a&gt; &lt;/p&gt;      &lt;br /&gt;      &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Web-Api-Debug-su-Azure_783C/image_4.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Web-Api-Debug-su-Azure_783C/image_thumb_1.png" width="244" height="105" /&gt;&lt;/a&gt;&lt;/p&gt;      &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Utilizzare la funzione &lt;i&gt;Attach debugger&lt;/i&gt; per il &lt;em&gt;Web Site&lt;/em&gt; oggetto del &lt;em&gt;Debug&lt;/em&gt;:       &lt;p&gt; &lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Web-Api-Debug-su-Azure_783C/image_10.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Web-Api-Debug-su-Azure_783C/image_thumb_4.png" width="244" height="193" /&gt;&lt;/a&gt;         &lt;br /&gt;&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;Si apre una nuova finestra del Browser con il &lt;em&gt;Web Site&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;Aggiungiamo dove necessario i &lt;em&gt;breakpoint&lt;/em&gt; nel codice (ad esempio su un’azione di GET del nostro &lt;em&gt;Controller&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;Invochiamo l’URL e per “magia” (la prima volta puo’ impiegare qualche di tempo) ci troviamo a debuggare la nostra applicazione appena pubblicata:      &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Web-Api-Debug-su-Azure_783C/image_12.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Web-Api-Debug-su-Azure_783C/image_thumb_5.png" width="244" height="72" /&gt;&lt;/a&gt;&lt;/p&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;N.B: I passi precedenti si riferiscono all’utilizzo di VS 2013, per VS 2012 bisogna abilitare il &lt;em&gt;remote debugging&lt;/em&gt; tramite il portale della nostra sottoscrizione Azure&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Web-Api-Debug-su-Azure_783C/image_14.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/Web-Api-Debug-su-Azure_783C/image_thumb_6.png" width="244" height="126" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.ugidotnet.org/pietrolibroblog/aggbug/101726.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Pietro Libro</dc:creator>
            <guid>http://blogs.ugidotnet.org/pietrolibroblog/archive/2013/11/19/web-api-e-debug-su-azure.aspx</guid>
            <pubDate>Tue, 19 Nov 2013 10:40:00 GMT</pubDate>
            <comments>http://blogs.ugidotnet.org/pietrolibroblog/archive/2013/11/19/web-api-e-debug-su-azure.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.ugidotnet.org/pietrolibroblog/comments/commentRss/101726.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.ugidotnet.org/pietrolibroblog/services/trackbacks/101726.aspx</trackback:ping>
        </item>
        <item>
            <title>VS 2013 (Preview) : ASP.NET External Authentication</title>
            <link>http://blogs.ugidotnet.org/pietrolibroblog/archive/2013/08/07/vs-2013-preview-external-authentication.aspx</link>
            <description>&lt;p&gt;Tra le novità di Visual Studio 2013 ed ASP.NET 4.5.1 , troviamo nuove opzioni per integrare applicazioni SPA (&lt;em&gt;Single Page Application&lt;/em&gt;) e Web API (ma non solo) con servizi di autenticazione esterni basati su Social come Twitter, Facebook, Google e Microsoft Accounts o basati su OAuth/OPenID (tutto a vantaggio di noi sviluppatori). Vediamo con un esempio.&lt;/p&gt;  &lt;p&gt;Apriamo VS 2013 (Preview) e selezioniamo come template “ASP.NET Web Application”:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/VS_7782/image_2.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/VS_7782/image_thumb.png" width="244" height="131" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Scegliamo il progetto di tipo SPA  che di base utilizza HTML5, CSS3 e ASP.NET Web API (una semplice applicazione “Todo List”):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/VS_7782/image_4.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/VS_7782/image_thumb_1.png" width="244" height="153" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;A questo punto il gioco è quasi finito, nella &lt;em&gt;Solution Explorer&lt;/em&gt; apriamo il file &lt;em&gt;App_Start\Startup.Auth.cs&lt;/em&gt; e decommentiamo la riga relativa “UseGoogleAuthentication”:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/VS_7782/image_6.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/VS_7782/image_thumb_2.png" width="241" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Eseguiamo l’applicazione con F5, e dalla schermata principale possiamo scegliere se autenticarci in modalità classica oppure utilizzando un servizio di autenticazione esterno (nello specifico “Google”):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/VS_7782/image_8.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/VS_7782/image_thumb_3.png" width="244" height="136" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Decommentando le opportune righe di codice è possibile offrire agli utenti piu’ servizi di autenticazione, ad esempio, per aggiungere anche “Microsoft Authentication” (è necessario possedere un account come developer qui : &lt;a title="http://go.microsoft.com/fwlink/?LinkID=144070" href="http://go.microsoft.com/fwlink/?LinkID=144070"&gt;http://go.microsoft.com/fwlink/?LinkID=144070&lt;/a&gt;)  modifichiamo il file di codice precedente aggiungendo “ClientId” and “Client Secret” come richiesto:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/VS_7782/image_14.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/VS_7782/image_thumb_6.png" width="244" height="213" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Eseguiamo con F5, ed ecco il risultato:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/VS_7782/image_10.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/Windows-Live-Writer/VS_7782/image_thumb_4.png" width="244" height="140" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Semplice, no ?&lt;/p&gt;  &lt;p&gt;Tutti gli approfondimenti del caso, sul sito di ASP.NET: &lt;a title="http://www.asp.net/web-api/overview/security/external-authentication-services" href="http://www.asp.net/web-api/overview/security/external-authentication-services"&gt;http://www.asp.net/web-api/overview/security/external-authentication-services&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.ugidotnet.org/pietrolibroblog/aggbug/101636.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Pietro Libro</dc:creator>
            <guid>http://blogs.ugidotnet.org/pietrolibroblog/archive/2013/08/07/vs-2013-preview-external-authentication.aspx</guid>
            <pubDate>Wed, 07 Aug 2013 10:13:00 GMT</pubDate>
            <comments>http://blogs.ugidotnet.org/pietrolibroblog/archive/2013/08/07/vs-2013-preview-external-authentication.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.ugidotnet.org/pietrolibroblog/comments/commentRss/101636.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.ugidotnet.org/pietrolibroblog/services/trackbacks/101636.aspx</trackback:ping>
        </item>
        <item>
            <title>ASP.NET and Web Tools 2012.2  : Web Api Help Page</title>
            <link>http://blogs.ugidotnet.org/pietrolibroblog/archive/2013/03/09/asp.net-and-web-tools-2012.2-web-api-page.aspx</link>
            <description>&lt;p&gt;Con il rilascio dell’&lt;a href="http://blogs.ugidotnet.org/PietroLibroBlog/archive/2013/02/20/asp.net-and-web-tools-2012.2-update.aspx" target="_blank"&gt;aggiornamento ASP.NET 2012.2&lt;/a&gt; di qualche settimana fa,  lo sviluppo di una “Help Page” per Web Api, utilizzando l’apposito &lt;em&gt;Package&lt;/em&gt; di NuGet, é un’attività che impegna meno di 5 minuti (per completezza di informazione, era già presente una versione alpha del &lt;em&gt;Package&lt;/em&gt; prima del rilascio ufficiale).&lt;/p&gt;
&lt;p&gt;1) Dalle “references” del progetto Web da “documentare”, apriamo la finestra per la gestione dei “Packages” di NuGet:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/WindowsLiveWriter/ASP.NETandWebTools2012.2WebApiPage_C1CA/image_2.png"&gt;&lt;img width="244" height="111" border="0" title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/WindowsLiveWriter/ASP.NETandWebTools2012.2WebApiPage_C1CA/image_thumb.png" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;2) Cerchiamo la voce “Web Api Help Page” e clicchiamo su “Install” (verranno installate le dipendenze necessarie):&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/WindowsLiveWriter/ASP.NETandWebTools2012.2WebApiPage_C1CA/image_4.png"&gt;&lt;img width="244" height="175" border="0" title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/WindowsLiveWriter/ASP.NETandWebTools2012.2WebApiPage_C1CA/image_thumb_1.png" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;3) Al progetto verrà aggiunta l’area “HelpPage” sotto la cartella “Areas”, con tutte le classi necessarie (&lt;em&gt;css&lt;/em&gt; compreso):&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/WindowsLiveWriter/ASP.NETandWebTools2012.2WebApiPage_C1CA/image_6.png"&gt;&lt;img width="244" height="175" border="0" title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/WindowsLiveWriter/ASP.NETandWebTools2012.2WebApiPage_C1CA/image_thumb_2.png" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;4) La classe &lt;em&gt;XmlDocumentationProvider  &lt;/em&gt;che&lt;em&gt; &lt;/em&gt;implementa l’interfaccia &lt;em&gt;IDocumentationProvider&lt;/em&gt; permette di documentare le nostre API nel caso più semplice utilizzando i commenti che decorano le Web API direttamente nel codice (implementando l’interfaccia &lt;em&gt;IDocumentationProvider &lt;/em&gt;é possibile personalizzare questo comportamento).&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/WindowsLiveWriter/ASP.NETandWebTools2012.2WebApiPage_C1CA/image_8.png"&gt;&lt;img width="244" height="69" border="0" title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/WindowsLiveWriter/ASP.NETandWebTools2012.2WebApiPage_C1CA/image_thumb_3.png" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;5) Aggiungiamo nel &lt;em&gt;Global.asax.cs&lt;/em&gt; la riga di codice seguente:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;config.Services.Replace(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IDocumentationProvider), &lt;span class="kwrd"&gt;new&lt;/span&gt; XmlDocumentationProvider(HttpContext.Current.Server.MapPath(&lt;span class="str"&gt;"~/App_Data/file.xml"&lt;/span&gt;)));&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;6) A questo punto non ci resta che eseguire la nostra applicazione e digitare “Help” nella barra degli indirizzi:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/WindowsLiveWriter/ASP.NETandWebTools2012.2WebApiPage_C1CA/image_10.png"&gt;&lt;img width="244" height="126" border="0" title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" alt="image" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/PietroLibroBlog/WindowsLiveWriter/ASP.NETandWebTools2012.2WebApiPage_C1CA/image_thumb_4.png" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;A questo punto é sufficiente passare alle personalizzazioni del caso :-).&lt;/p&gt;&lt;img src="http://blogs.ugidotnet.org/pietrolibroblog/aggbug/101466.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Pietro Libro</dc:creator>
            <guid>http://blogs.ugidotnet.org/pietrolibroblog/archive/2013/03/09/asp.net-and-web-tools-2012.2-web-api-page.aspx</guid>
            <pubDate>Sat, 09 Mar 2013 14:46:00 GMT</pubDate>
            <comments>http://blogs.ugidotnet.org/pietrolibroblog/archive/2013/03/09/asp.net-and-web-tools-2012.2-web-api-page.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.ugidotnet.org/pietrolibroblog/comments/commentRss/101466.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.ugidotnet.org/pietrolibroblog/services/trackbacks/101466.aspx</trackback:ping>
        </item>
    </channel>
</rss>