{"id":783,"date":"2012-04-11T16:05:59","date_gmt":"2012-04-11T16:05:59","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/odatateam\/2012\/04\/11\/what-happened-to-applicationjson-in-wcf-ds-5-0\/"},"modified":"2012-04-11T16:05:59","modified_gmt":"2012-04-11T16:05:59","slug":"what-happened-to-applicationjson-in-wcf-ds-5-0","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/odata\/what-happened-to-applicationjson-in-wcf-ds-5-0\/","title":{"rendered":"What happened to application\/json in WCF DS 5.0?"},"content":{"rendered":"<h2>The roadmap for serialization formats<\/h2>\n<p>We have been talking <a href=\"https:\/\/www.odata.org\/blog\/2011\/3\/25\/an-efficient-format-for-odata\">for a while<\/a> about a <a href=\"https:\/\/www.odata.org\/blog\/2012\/1\/19\/format-efficiency-take-2-really-clean-json\">more efficient format<\/a> for JSON serialization. The new serialization format will be part of the OData v3 protocol, and we believe that <b>the much-improved JSON format should be the default response when requesting application\/json<\/b>.<\/p>\n<p>You may notice that when you upgrade to WCF DS 5.0, requesting the old JSON format is a bit different. To get the old JSON format, you must now explicitly request application\/json;odata=verbose or set the MaxDataServiceVersion header to 2.0.<\/p>\n<h2>When will I get a 415 response and what can I do about it?<\/h2>\n<p>WCF Data Services 5.0 will return a 415 in response to a request for application\/json if the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.data.services.dataservicebehavior.maxprotocolversion.aspx\">service configuration allows a v3 response<\/a> and if the client does not specify a MaxDataServiceVersion header or specifies a MaxDataServiceVersion header of 3.0. <b>Clients should always send a value for the MaxDataServiceVersion header to ensure forward compatibility.<\/b><\/p>\n<p>There are two ways to get a response formatted with JSON verbose:<\/p>\n<p>1. Set the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd541103(v=PROT.10).aspx\">MaxDataServiceVersion header<\/a> to 2.0 or less. For instance:<\/p>\n<blockquote>\n<p><font size=\"2\" face=\"Consolas\">GET <\/font><a href=\"http:\/\/odata.example.org\/Items?$top=5\"><font size=\"2\" face=\"Consolas\">http:\/\/odata.example.org\/Items?$top=5<\/font><\/a><font size=\"2\" face=\"Consolas\"> HTTP\/1.1<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">Host: odata.example.org<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">Connection: keep-alive<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">User-Agent: Mozilla\/5.0 (Windows NT 6.2; WOW64) AppleWebKit\/535.19 (KHTML, like Gecko) Chrome\/18.0.1025.152 Safari\/535.19<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">Accept: application\/json<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">Accept-Encoding: gzip,deflate,sdch<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">Accept-Language: en-US,en;q=0.8<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">MaxDataServiceVersion: 2.0<\/font><\/p>\n<\/blockquote>\n<p>2. Request a content type of <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd541269(v=prot.10).aspx\">application\/json;odata=verbose<\/a>. For instance:<\/p>\n<blockquote>\n<p><font size=\"2\" face=\"Consolas\">GET <\/font><a href=\"http:\/\/odata.example.org\/Items?$top=5\"><font size=\"2\" face=\"Consolas\">http:\/\/odata.example.org\/Items?$top=5<\/font><\/a><font size=\"2\" face=\"Consolas\"> HTTP\/1.1<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">Host: odata.example.org<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">Connection: keep-alive<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">User-Agent: Mozilla\/5.0 (Windows NT 6.2; WOW64) AppleWebKit\/535.19 (KHTML, like Gecko) Chrome\/18.0.1025.152 Safari\/535.19<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">Accept: application\/json;odata=verbose<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">Accept-Encoding: gzip,deflate,sdch<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">Accept-Language: en-US,en;q=0.8<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3<\/font><\/p>\n<p><font size=\"2\" face=\"Consolas\">MaxDataServiceVersion: 3.0<\/font><\/p>\n<\/blockquote>\n<p>It\u2019s possible to modify the headers with jQuery as follows:<\/p>\n<blockquote>\n<p style=\"margin: 0in 0in 0pt;background: white\" class=\"MsoNormal\"><span style=\"font-family:;color:\"><font face=\"Consolas\"><font style=\"font-size: 10pt\">$.ajax(url, {<\/font><\/font><\/span><\/p>\n<p style=\"margin: 0in 0in 0pt;background: white\" class=\"MsoNormal\"><font face=\"Consolas\"><span style=\"font-family:;color:\"><font style=\"font-size: 10pt\">&#160;&#160;&#160; dataType: <\/font><\/span><font style=\"font-size: 10pt\"><span style=\"font-family:;color:\"><font color=\"#800000\">&quot;json&quot;, <\/font><\/span><\/font><span style=\"font-family:;color:\"><font style=\"font-size: 10pt\" color=\"#77933c\">\/\/ this tells jquery that you are expcting a json object and so it will parse the data for you.<\/font><\/span><\/font><span style=\"font-family:;color:\"><\/span><\/p>\n<p style=\"margin: 0in 0in 0pt;background: white\" class=\"MsoNormal\"><font face=\"Consolas\"><span style=\"font-family:;color:\"><font style=\"font-size: 10pt\">&#160;&#160;&#160; beforeSend: <\/font><\/span><font style=\"font-size: 10pt\"><span style=\"font-family:;color:\"><font color=\"#0000ff\">function<\/font><\/span><\/font><span style=\"font-family:;color:\"><font style=\"font-size: 10pt\"> (xhr) {<\/font><\/span><\/font><\/p>\n<p style=\"margin: 0in 0in 0pt;background: white\" class=\"MsoNormal\"><font face=\"Consolas\"><span style=\"font-family:;color:\"><font style=\"font-size: 10pt\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; xhr.setRequestHeader(<\/font><\/span><font style=\"font-size: 10pt\"><span style=\"font-family:;color:\"><font color=\"#800000\">&quot;Accept&quot;<\/font><\/span><span style=\"font-family:;color:\">, <\/span><span style=\"font-family:;color:\"><font color=\"#800000\">&quot;application\/json;odata=verbose&quot;<\/font><\/span><\/font><span style=\"font-family:;color:\"><font style=\"font-size: 10pt\">);<\/font><\/span><\/font><\/p>\n<p style=\"margin: 0in 0in 0pt;background: white\" class=\"MsoNormal\"><font face=\"Consolas\"><span style=\"font-family:;color:\"><font style=\"font-size: 10pt\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; xhr.setRequestHeader(<\/font><\/span><font style=\"font-size: 10pt\"><span style=\"font-family:;color:\"><font color=\"#800000\">&quot;MaxDataServiceVersion&quot;<\/font><\/span><span style=\"font-family:;color:\">, <\/span><span style=\"font-family:;color:\"><font color=\"#800000\">&quot;3.0&quot;<\/font><\/span><\/font><span style=\"font-family:;color:\"><font style=\"font-size: 10pt\">);<\/font><\/span><\/font><\/p>\n<p style=\"margin: 0in 0in 0pt;background: white\" class=\"MsoNormal\"><span style=\"font-family:;color:\"><font face=\"Consolas\"><font style=\"font-size: 10pt\">&#160;&#160;&#160; },<\/font><\/font><\/span><\/p>\n<p style=\"margin: 0in 0in 0pt;background: white\" class=\"MsoNormal\"><font face=\"Consolas\"><span style=\"font-family:;color:\"><font style=\"font-size: 10pt\">&#160;&#160;&#160; success: <\/font><\/span><font style=\"font-size: 10pt\"><span style=\"font-family:;color:\"><font color=\"#0000ff\">function<\/font><\/span><\/font><span style=\"font-family:;color:\"><font style=\"font-size: 10pt\"> (data) {<\/font><\/span><\/font><\/p>\n<p style=\"margin: 0in 0in 0pt;background: white\" class=\"MsoNormal\"><font face=\"Consolas\"><span style=\"font-family:;color:\"><font style=\"font-size: 10pt\">&#160;&#160;&#160;&#160;&#160;&#160; <\/font><\/span><span style=\"font-family:;color:\"><font style=\"font-size: 10pt\" color=\"#77933c\">\/\/ do something interesting with the data you get back.<\/font><\/span><\/font><\/p>\n<p style=\"margin: 0in 0in 0pt;background: white\" class=\"MsoNormal\"><span style=\"font-family:;color:\"><font face=\"Consolas\"><font style=\"font-size: 10pt\">&#160;&#160;&#160; }<\/font><\/font><\/span><\/p>\n<p style=\"margin: 0in 0in 0pt;background: white\" class=\"MsoNormal\"><span style=\"font-family:;color:\"><font face=\"Consolas\"><font style=\"font-size: 10pt\">});<\/font><\/font><\/span><\/p>\n<\/blockquote>\n<h2>Why did WCF DS 5.0 ship before JSON light?<\/h2>\n<p>We had a set of features that were ready to be released as part of WCF DS 5.0. The more efficient JSON implementation is currently in progress and will be released sometime later this year.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The roadmap for serialization formats We have been talking for a while about a more efficient format for JSON serialization. The new serialization format will be part of the OData v3 protocol, and we believe that the much-improved JSON format should be the default response when requesting application\/json. You may notice that when you upgrade [&hellip;]<\/p>\n","protected":false},"author":512,"featured_media":3253,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-783","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-odata"],"acf":[],"blog_post_summary":"<p>The roadmap for serialization formats We have been talking for a while about a more efficient format for JSON serialization. The new serialization format will be part of the OData v3 protocol, and we believe that the much-improved JSON format should be the default response when requesting application\/json. You may notice that when you upgrade [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/users\/512"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/comments?post=783"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/783\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media\/3253"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media?parent=783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/categories?post=783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/tags?post=783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}