{"id":164945,"date":"2013-01-08T12:21:03","date_gmt":"2013-01-08T08:21:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=164945"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=164945","title":{"rendered":"<span class=\"post_title\">RESTFul Api \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0432 .NET MVC 4<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" align=\"right\" src=\"http:\/\/habrastorage.org\/storage2\/109\/10f\/399\/10910f39999605402c8fb0fecf0edf60.png\"\/> \u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e.<br \/>  \u041b\u0435\u0442\u043e\u043c \u0432\u044b\u0448\u0435\u043b \u0440\u0435\u043b\u0438\u0437 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u043d\u043e \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u043e. \u0412 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0448\u0442\u0443\u043a, \u043e\u0431 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e ApiController, \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c.<br \/>  \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0438\u043c \u0441\u0442\u0430\u043b\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c RESTFull Api \u0431\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u0443\u0441\u0438\u043b\u0438\u0439. \u041d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0437\u0430\u043e\u0434\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 OData.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 ASP MVC 4<b> Empty Project<\/b>. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0442\u043e\u043f\u0438\u043a\u0430\u043c\u0438. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c:  <\/p>\n<pre><code class=\"cs\">public class Topic {     public int Id { get; set; }      public string Title { get; set; } } <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0435\u0433\u043e \u043e\u0442 <b>ApiController<\/b>, \u043f\u043e\u043a\u0430 \u0431\u0435\u0437 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439:   <\/p>\n<pre><code class=\"cs\">public class TopicController : ApiController { } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443: <b><a href=\"http:\/\/localhost\/api\/topic\">localhost\/api\/topic<\/a><\/b>. \u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043f\u043e \u043d\u0435\u043c\u0443, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0435\u0433\u043e \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 GET \u0437\u0430\u043f\u0440\u043e\u0441. \u0422\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0436\u0435 \u0435\u0433\u043e \u0432 \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:  <\/p>\n<pre><code class=\"cs\">public class TopicController : ApiController {     public ICollection&lt;Topic&gt; Get()     {         return new Collection&lt;Topic&gt;                     {                         new Topic { Id = 1, Title = &quot;\u0422\u043e\u043f\u0438\u043a 1&quot;},                         new Topic { Id = 2, Title = &quot;\u0422\u043e\u043f\u0438\u043a 2&quot;}                     };     }  } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 <b><a href=\"http:\/\/localhost\/api\/topic\">localhost\/api\/topic<\/a><\/b>, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043e\u0442\u0432\u0435\u0442:  <\/p>\n<pre><code class=\"xml\">&lt;ArrayOfTopicModel xmlns:i=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xmlns=&quot;http:\/\/schemas.datacontract.org\/2004\/07\/ApiControllerTutorial.Models&quot;&gt;     &lt;TopicModel&gt;         &lt;Id&gt;1&lt;\/Id&gt;         &lt;Title&gt;\u0422\u043e\u043f\u0438\u043a 1&lt;\/Title&gt;     &lt;\/TopicModel&gt;     &lt;TopicModel&gt;         &lt;Id&gt;2&lt;\/Id&gt;         &lt;Title&gt;\u0422\u043e\u043f\u0438\u043a 2&lt;\/Title&gt;     &lt;\/TopicModel&gt; &lt;\/ArrayOfTopicModel&gt; <\/code><\/pre>\n<p>  \u041f\u043e\u0447\u0435\u043c\u0443 \u043e\u0442\u0432\u0435\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 XML? \u041f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043b\u0438 <b>Content-Type<\/b> \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435, \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u0435\u0440\u043d\u0435\u0442 \u043d\u0430\u043c XML. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f Chromium \u2014 <b>REST Console<\/b> (\u0437\u0430 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0443 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432\/\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432 \u0431\u0443\u0434\u0443 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0435\u043d). \u0423\u043a\u0430\u0436\u0435\u043c \u0432 <b>Content-Type<\/b> <b>\u00abjson\u00bb<\/b> \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c:   <\/p>\n<pre><code class=\"xml\">[{&quot;Id&quot;:1,&quot;Title&quot;:&quot;\u0422\u043e\u043f\u0438\u043a 1&quot;},{&quot;Id&quot;:2,&quot;Title&quot;:&quot;\u0422\u043e\u043f\u0438\u043a 2&quot;}] <\/code><\/pre>\n<p>  \u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0442\u043e\u043f\u0438\u043a\u043e\u0432 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u043e\u043f\u0438\u043a\u0430 \u043f\u043e \u0435\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443:  <\/p>\n<pre><code class=\"cs\">public Topic Get(int id) {     return new Topic                 {                     Id = id,                     Title = String.Format(&quot;\u0422\u043e\u043f\u0438\u043a {0}&quot;, id)                 }; } <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <b><a href=\"http:\/\/localhost\/api\/topic\/5\">localhost\/api\/topic\/5<\/a><\/b> \u0432\u0435\u0440\u043d\u0435\u0442 \u043d\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043e\u0442\u0432\u0435\u0442:  <\/p>\n<pre><code class=\"xml\">{&quot;Id&quot;:5,&quot;Title&quot;:&quot;\u0422\u043e\u043f\u0438\u043a 5&quot;} <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u043e\u043f\u0438\u043a\u0430:  <\/p>\n<pre><code class=\"cs\">public string Put(Topic model) {     return String.Format(&quot;\u0422\u043e\u043f\u0438\u043a '{0}' \u0441\u043e\u0437\u0434\u0430\u043d!&quot;, model.Title); } <\/code><\/pre>\n<p>  \u0418 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <b><a href=\"http:\/\/localhost\/api\/topic\/\">localhost\/api\/topic\/<\/a><\/b> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:  <\/p>\n<pre><code class=\"xml\">{'Title':'\u041d\u043e\u0432\u044b\u0439 \u0442\u043e\u043f\u0438\u043a'} <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0443\u043a\u0430\u0436\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: <b>Request Method<\/b> \u2014 <b>PUT<\/b> \u0438 <b>Content type<\/b> \u2014 <b>application\/json<\/b> (\u041d\u0435 \u043f\u0435\u0440\u0435\u043f\u0443\u0442\u0430\u0439\u0442\u0435 \u044d\u0442\u043e\u0442 Content type \u0441 \u0442\u0435\u043c, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u044f \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u0432\u044b\u0448\u0435. \u042d\u0442\u043e\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 <b>Content Headers<\/b>, \u0447\u0442\u043e\u0431\u044b \u0431\u0430\u0439\u043d\u0434\u0435\u0440 \u0437\u043d\u0430\u043b, \u0432 \u043a\u0430\u043a\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043f\u0440\u0438\u0448\u043b\u0438 \u043a \u043d\u0435\u043c\u0443 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0442\u043e\u043f\u0438\u043a\u043e\u0432 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438 Content type \u0432 <b>Accept<\/b> \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430). \u0418 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0432 \u043e\u0442\u0432\u0435\u0442:   <\/p>\n<pre><code class=\"xml\">&quot;\u0422\u043e\u043f\u0438\u043a '\u041d\u043e\u0432\u044b\u0439 \u0442\u043e\u043f\u0438\u043a' \u0441\u043e\u0437\u0434\u0430\u043d!&quot; <\/code><\/pre>\n<p>  \u041a\u0441\u0442\u0430\u0442\u0438 \u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u0432\u0435\u0440\u043d\u0443\u043b \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c. \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <b>HttpResponseMessage<\/b> \u0438 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434\u0430\u043c\u0438 \u043e\u0442\u0432\u0435\u0442\u0430, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0443\u0441\u043f\u0435\u0445\u0430\/\u043d\u0435\u0443\u0434\u0430\u0447\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:  <\/p>\n<pre><code class=\"cs\">public HttpResponseMessage Put(Topic model) {     if(String.IsNullOrEmpty(model.Title))         return new HttpResponseMessage(HttpStatusCode.BadRequest);      \/*\u041b\u043e\u0433\u0438\u043a\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f*\/      return new HttpResponseMessage(HttpStatusCode.Created); } <\/code><\/pre>\n<p>  \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <b>POST<\/b> \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443, \u0442.\u043a. \u043e\u0442\u043b\u0438\u0447\u0438\u0439 \u043e\u0442 <b>PUT<\/b> \u2014 \u043d\u0435\u0442. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 <b>DELETE<\/b>:  <\/p>\n<pre><code class=\"cs\">public string Delete(int id) {     return String.Format(&quot;\u0422\u043e\u043f\u0438\u043a {0} \u0443\u0434\u0430\u043b\u0435\u043d!&quot;, id); } <\/code><\/pre>\n<h1>\u0420\u043e\u0443\u0442\u0438\u043d\u0433<\/h1>\n<p>  \u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0430\u043f\u0438, \u0431\u0435\u0437 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432?<br \/>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0441 \u0434\u0432\u0443\u043c\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u043c\u0438:  <\/p>\n<pre><code class=\"cs\">public class TestRouteController : ApiController {     public string GetTopic(int id)     {         return String.Format(&quot;Topic {0}&quot;, id);     }      public string GetComment(int id)     {         return String.Format(&quot;Comment {0}&quot;, id);     } } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 <b><a href=\"http:\/\/localhost\/api\/testroute\/5\">localhost\/api\/testroute\/5<\/a><\/b>, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443: <b>Multiple actions were found that match the request<\/b>. \u0421\u0432\u044f\u0437\u0430\u043d\u043e \u044d\u0442\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e Selector \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043a\u0430\u043a\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0435\u043c\u0443 \u0432\u044b\u0431\u0440\u0430\u0442\u044c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0442\u043a\u0440\u043e\u0435\u043c WebApiConfig.cs \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0430\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442:  <\/p>\n<pre><code class=\"cs\">public static void Register(HttpConfiguration config) {     config.Routes.MapHttpRoute(         name: &quot;DefaultApi&quot;,         routeTemplate: &quot;api\/{controller}\/{id}&quot;,         defaults: new { id = RouteParameter.Optional }     ); } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0443 \u043d\u0430\u0441 \u043d\u0435 \u0437\u0430\u0434\u0430\u043d\u043e \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Method&#8217;a \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0438\u0436\u0435 \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043c\u0430\u0440\u0448\u0440\u0443\u0442:  <\/p>\n<pre><code class=\"cs\">config.Routes.MapHttpRoute(                 name: &quot;DefaultApiWithAction&quot;,                 routeTemplate: &quot;api\/{controller}\/{action}\/{id}&quot;,                 defaults: new { id = RouteParameter.Optional }             ); <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0443 \u0441 \u043f\u0440\u044f\u043c\u044b\u043c \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (<b><a href=\"http:\/\/localhost\/api\/testroute\/gettopic\/5\">localhost\/api\/testroute\/gettopic\/5<\/a><\/b>), \u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0442\u0432\u0435\u0442. \u041b\u0438\u0431\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0443 \u0441\u0430\u043c\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 <b>ActionName<\/b>:  <\/p>\n<pre><code class=\"cs\">[ActionName(&quot;topic&quot;)] public string GetTopic(int id) {     return String.Format(&quot;Topic {0}&quot;, id); } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c <b><a href=\"http:\/\/localhost\/api\/testroute\/topic\/5\">localhost\/api\/testroute\/topic\/5<\/a><\/b><\/p>\n<h1>OData<\/h1>\n<p>  \u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043b\u0438\u0431\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b. \u0420\u0430\u043d\u044c\u0448\u0435 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u043b\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <b>ActionResult<\/b>, \u0438 \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435. \u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c OData (<a href=\"http:\/\/www.nuget.org\/packages\/Microsoft.AspNet.WebApi.OData\/\">Nuget<\/a>) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430:  <\/p>\n<blockquote><p>PM&gt; Install-Package Microsoft.AspNet.WebApi.OData -Pre<\/p><\/blockquote>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:  <\/p>\n<pre><code class=\"cs\">public class OdataController : ApiController {     [Queryable]     public IQueryable&lt;Topic&gt; Get()     {         return new             EnumerableQuery&lt;Topic&gt;(             new Collection&lt;Topic&gt;                 {                     new Topic{ Id = 1, Title = &quot;1&quot;},                     new Topic{ Id = 2, Title = &quot;2&quot;},                     new Topic{ Id = 3, Title = &quot;3&quot;},                     new Topic{ Id = 4, Title = &quot;4&quot;},                     new Topic{ Id = 5, Title = &quot;5&quot;}                 });     } } <\/code><\/pre>\n<p>  \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 <b><a href=\"http:\/\/localhost\/api\/odata\/\">localhost\/api\/odata\/<\/a><\/b>:  <\/p>\n<pre><code class=\"xml\">[{&quot;Id&quot;:1,&quot;Title&quot;:&quot;1&quot;},{&quot;Id&quot;:2,&quot;Title&quot;:&quot;2&quot;},{&quot;Id&quot;:3,&quot;Title&quot;:&quot;3&quot;},{&quot;Id&quot;:4,&quot;Title&quot;:&quot;4&quot;},{&quot;Id&quot;:5,&quot;Title&quot;:&quot;5&quot;}] <\/code><\/pre>\n<p>  \u041d\u0438\u0447\u0435\u0433\u043e \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e. \u041d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 Get \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <b>IQueryable<\/b> \u0438 \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c <b> [Queryable]<\/b>, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OData \u043f\u0440\u044f\u043c\u043e \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435. \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u0442\u0432\u0435\u0442:  <\/p>\n<table>\n<tr>\n<th>\u0417\u0430\u043f\u0440\u043e\u0441<\/th>\n<th>\u041e\u0442\u0432\u0435\u0442<\/th>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/localhost\/api\/odata\/\">localhost\/api\/odata\/<\/a><\/td>\n<td>[{\u00abId\u00bb:1,\u00abTitle\u00bb:\u00ab1\u00bb},<br \/>  {\u00abId\u00bb:2,\u00abTitle\u00bb:\u00ab2\u00bb},<br \/>  {\u00abId\u00bb:3,\u00abTitle\u00bb:\u00ab3\u00bb},<br \/>  {\u00abId\u00bb:4,\u00abTitle\u00bb:\u00ab4\u00bb},<br \/>  {\u00abId\u00bb:5,\u00abTitle\u00bb:\u00ab5\u00bb}]<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/localhost\/api\/odata\/\">localhost\/api\/odata\/<\/a>?$skip=2<\/td>\n<td>[{\u00abId\u00bb:3,\u00abTitle\u00bb:\u00ab3\u00bb},<br \/>  {\u00abId\u00bb:4,\u00abTitle\u00bb:\u00ab4\u00bb},<br \/>  {\u00abId\u00bb:5,\u00abTitle\u00bb:\u00ab5\u00bb}]<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/localhost\/api\/odata\/\">localhost\/api\/odata\/<\/a>?$skip=1&#038;$top=2<\/td>\n<td>[{\u00abId\u00bb:2,\u00abTitle\u00bb:\u00ab2\u00bb},<br \/>  {\u00abId\u00bb:3,\u00abTitle\u00bb:\u00ab3\u00bb}]<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/localhost\/api\/odata\/\">localhost\/api\/odata\/<\/a>?$filter=(Id gt 1) and (Id lt 5)<\/td>\n<td>[{\u00abId\u00bb:2,\u00abTitle\u00bb:\u00ab2\u00bb},<br \/>  {\u00abId\u00bb:3,\u00abTitle\u00bb:\u00ab3\u00bb},<br \/>  {\u00abId\u00bb:4,\u00abTitle\u00bb:\u00ab4\u00bb}]<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/localhost\/api\/odata\/\">localhost\/api\/odata\/<\/a>?$filter=(Id gt 1) and (Id lt 5)&#038;$orderby=Id desc<\/td>\n<td>[{\u00abId\u00bb:4,\u00abTitle\u00bb:\u00ab4\u00bb},<br \/>  {\u00abId\u00bb:3,\u00abTitle\u00bb:\u00ab3\u00bb},<br \/>  {\u00abId\u00bb:2,\u00abTitle\u00bb:\u00ab2\u00bb}]<\/td>\n<\/tr>\n<\/table>\n<p>  \u041c\u0430\u0433\u0438\u044f, \u043d\u0435 \u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438?<\/p>\n<hr\/>\n<p>  \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0444\u043e\u0440\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u043c: <a href=\"http:\/\/www.asp.net\/web-api\/overview\/working-with-http\/sending-html-form-data,-part-1#sending_complex_types\">http:\/\/www.asp.net\/web-api\/overview\/working-with-http\/sending-html-form-data,-part-1#sending_complex_types<\/a><br \/>  \u0412\u0441\u0435 \u043f\u0440\u043e OData: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff478141.aspx\">http:\/\/msdn.microsoft.com\/en-us\/library\/ff478141.aspx<\/a><br \/>  \u0410\u0440\u0445\u0438\u0432 \u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c: <a href=\"http:\/\/yadi.sk\/d\/k2KaG0cL1fXhA\">yadi.sk\/d\/k2KaG0cL1fXhA<\/a>    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/164945\/\"> http:\/\/habrahabr.ru\/post\/164945\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" align=\"right\" src=\"http:\/\/habrastorage.org\/storage2\/109\/10f\/399\/10910f39999605402c8fb0fecf0edf60.png\"\/> \u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e.<br \/>  \u041b\u0435\u0442\u043e\u043c \u0432\u044b\u0448\u0435\u043b \u0440\u0435\u043b\u0438\u0437 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u043d\u043e \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u043e. \u0412 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0448\u0442\u0443\u043a, \u043e\u0431 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e ApiController, \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c.<br \/>  \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0438\u043c \u0441\u0442\u0430\u043b\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c RESTFull Api \u0431\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u0443\u0441\u0438\u043b\u0438\u0439. \u041d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0437\u0430\u043e\u0434\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 OData.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-164945","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/164945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=164945"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/164945\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=164945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=164945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=164945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}