Update from webapi Beta to webapi RC

Source: Internet
Author: User
Tags http cookie

The official word on changes from Beta to RC for web API-related topics (filtered from the original page ).

  • ASP. NET web API now uses JSON. Net for JSON formatting:The default JSON formatter in ASP. NET web API now uses JSON. Net for JSON serialization. JSON. NET provides the flexibility and performance required for a modern Web framework.
  • Formatter improvements:The methods onMediatypeformatterAre now public to enable unit testing of custom formatters. A single formatter can now support multiple text encodings. UseBufferedmediatypeformatterTo implement simple synchronous formatting support.FormattercontextHas been removed. To get access to the request from a formatter on the server implementGetperrequestformatterinstance.
  • Removed system. JSON. dll:Because of the overlap with functionality already in JSON. Net the system. JSON. dll assembly has been removed.
  • Xmlmediatypeformatter uses datacontractserializer by default:TheXmlmediatypeformatterNow usesDatacontractserializerBy default. This means that by default ASP. NET web API will use the data contract Programming Model for formatting types. You can configureXmlmediatypeformatterTo useXmlserializerBy settingUsexmlserializerTo true.
  • formatters now always handle the body content: Asp. net web API formatters are now used consistently for handling both the request and response content. we have removed irequestcontentreadpolicy . the formurlencodedmediatypeformatter class has been updated to use MVC-style model binding, so you can still use model binding infrastructure for handling form data in the Request body.
  • HTTP content negotiation decoupled fromObjectcontent:Previusly in ASP. NET web API all HTTP content negotiation logic was encapsulated inObjectcontent, Which made it difficult to predict when HTTP content negotiation wowould occur. We have decoupled HTTP content negotiation fromObjectcontentAnd encapsulated it asIcontentnegotiatorImplementation.ObjectcontentNow takes a single formatter. You can run HTTP content negotiation whenever you want usingDefaultcontentnegotiatorImplementation to select an appropriate formatter.IformatterselectorHas been removed
  • RemovedHttprequestmessage <t>AndHttpresponsemessage <t>: Previusly there were two ways to specify a request or response with Objectcontent Instance: You cocould provide Objectcontent Instance directly, or you cocould use Httprequestmessage <t> Or Httpresponsemessage <t> . Having two ways of doing the same thing complicated request and Response Handling, so Httprequestmessage <t> And Httpresponsemessage <t> Have been removed. To create content negotiated responses that contain Objectcontent Use Createresponse <t> Extension methods on the request message. To send a request that contains Objectcontent Use Postasync <t> Extension methods on Httpclient . Or, use Postasjsonasync <t> And Postasxmlasync <t> Extension methods to specify a request that will be specifically formatted with as JSON or XML respectively.
  • Simplified action parameter binding:You can now predictably determine whether an action parameter will be bound to the Request body. this ensures that the request stream is not unnecessarily consumed. parameters with simple types by default come from the URL. parameters with complex types by default come from the body. there can be only one body parameter. you can explain icitly specify if a parameter comes from the URL or from the body using[Fromuri]And[Frombody]Attributes.
  • query composition is now implemented as a reusable filter: previusly support for query composition was hard coded into the runtime. query composition is now implemented as a reusable filter that can be applied as an attribute ( [queryable] ) to any action that returns an iqueryable instance. this attribute is now required to enable query composition.
  • Cookies:TheHttprequestmessageAndHttpresponsemessageClasses expose the HTTP cookie and set-Cookie headers as raw strings and not structured classes. this made it cumbersome and error prone to work with cookies in ASP. net web API. to fix this we introduced two newCookieheadervalueAndCookiestateThat follow RFC 6265 HTTP state management mechanisms. You can useAddcookiesExtension Method to add a set-Cookie header to a response message. UseGetcookiesExtension Method to get all ofCookieheadervaluesFrom a request.
  • Httpmessageinvoker:TheHttpmessageinvokerProvides a light weight mechanic to invokeHttpmessagehandlerWithout the overhead of usingHttpclient. UseHttpmessageinvokerFor unit testing message handlers and also for invoking message handlers on the server.
  • Response buffering improvements:When web-hosting a web API the response content length is now set intelligently so that responses are not always chunked. Buffering also enables reasonable error messages to be returned when exceptions occur in formatters.
  • Independently control ihttpcontroller selection and activation:ImplementIhttpcontrollerselectorTo controlIhttpcontrollerSelection. ImplementIhttpcontrolleractivatorTo controlIhttpcontrollerActivation.IhttpcontrollerfactorySpecified action has been removed.
  • Clearer integration with IOC containers that support scopes:The dependency resolver for ASP. net web API now supports creating dependency scopes that can be independently disposed. A dependency scope is created for each request and is used for controller activation. processing dependency resolution (I. e.Httpconfiguration. dependencyresolver) Is optional and is now configured separately from the default services used by ASP. NET web API (Httpconfiguration. Services). However, the service locator consults the dependency resolver first for required services and then falls back to explicitly configured services.
  • Improved Link generation:The ASP. NET web APIUrlhelperHow has convenience methods for generating links based on the configured routes and the request URI.
  • Register resource for disposal at the end of the request life-time:UseRegisterfordisposeExtension Method on the request to register an idisposable instance that shocould be disposed when the request is disposed.
  • Monitoring and diagnostics:You can enable tracing by providingItracewriterImplementation and processing ing it as a service using the dependency resolver.IloggerInterface has been removed.
  • Create custom help and test pages:You now can easily build custom help and test pages for your Web APIs by using the newIapiexplorerService to get a complete runtime description of your Web APIs.
  • Entity Framework based scaffolding for Web APIs:UseAdd ControllerDialog to quickly scaffold a web API controller based on an Entity Framework based model type.
  • Create unit test projects for web API projects:You can now easily create a unit test project for a web API project usingNew ASP. net mvc 4 ProjectDialog box.
  • Unauthorized requests handled by ASP. NET web API return 401 unauthroized:Unauthorized requests handled by ASP. NET web API now return a standard 401 unauthorized response instead of redirecting the user agent to a login form so that the response can be handled by an Ajax client.
  • Configuration logic for MVC applications moved under the app_start directory:The configuration logic for MVC applications has been moved from global. asax. CS to a set of static classes in the app_start directory. routes are registered in routeconfig. CS. global MVC filters are registered in filterconfig. CS. bundling and minification configuration now lives in bundleconfig. CS.
  • Add controller to any project folder:You can now right click and selectAdd ControllerFrom any folder in your MVC project. This gives you more flexibility to organize your controllers however you want, including keeping your MVC and web API controllers in separate folders.

See this articleArticleTips for updating from webapi Beta to webapi RC. We have summarized the update of webapi Beta to webapi RC, and made some special notes.

1. nuget packages: The nuget packages name of the webapi from Beta to RC has changed.Microsoft. ASPnet. webapi:

2. Dependency injection: the author uses ninject. This article describes how to set dependencyresolver: Using ninject with the latest ASP. net web API source, I like to use autofac, you can directly update autofac ASP through nuget package.. NET web API (RC) Integration

3. The generic httpresponsemessage has been replaced: Beta'sCodeUsed inNew httpresponsemessage <t> (somevalue) must be changed toRequest attributes

Request. createresponse (httpstatuscode. OK, result );

4. You no longer need to customize JSON. Net formatter. rc json. NET is now the default serialization tool for Web APIs,The redundant system. JSON. dll has been removed. As Microsoft said:

JSON. NET provides flexibility and performance for a modern Web framework.

VaR formatter = globalconfiguration. configuration. formatters. Where (F =>
{
Return F. supportedmediatypes. Any (V => v. mediatype. Equals ("application/JSON", stringcomparison. currentcultureignorecase ));
}). Firstordefault () as jsonmediatypeformatter;
If (formatter! = NULL)
{
Formatter. serializersettings = new jsonserializersettings ()
{
Nullvaluehandling = nullvaluehandling. Ignore,
Converters = new jsonconverter [] {New isodatetimeconverter ()}
// Whatever else you need...
};
}

5. The extension method getuserprincipal does not exist. You can use it in the Custom authorize attribute.System. Threading. thread. currentprincipal. Identity, you can also use the attribute user in apicontroller.

6. Parameter Binder: http://www.cnblogs.com/xiaoweiyu/archive/2012/06/12/2546116.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.