Text version of the video
http://csharp-video-tutorials.blogspo...
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
/ @aarvikitchen5572
Slides
http://csharp-video-tutorials.blogspo...
All ASP .NET Web API Text Articles and Slides
http://csharp-video-tutorials.blogspo...
All ASP .NET Web API Videos
• ASP.NET Web API tutorial for beginners
All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenka...
All Dot Net and SQL Server Tutorials in Arabic
/ kudvenkatarabic
In this video we will discuss versioning a Web Service using a QueryString parameter.
Before we implement versioning using a querystring parameter. First let's understand how a controller is selected when a request is issued to a web api service. For example, let us understand how a controller is selected when a rquest is issued to the following URI
/api/students/1
In Web API, there is a class called DefaultHttpControllerSelector. This class has a method called SelectController() that selects the controller based on the information it has in the URI.
In the URI we have
1. The name of the controller, in this case students
2. The id parameter value, in this case 1
So from the URI, the SelectController() method takes the name of the controller in this case "Students" and finds "StudentsController" and returns it. This is the default implementation that we get out of the box.
This default implementation will not work for us because, in our service we do not have controller that is named StudentsController. Instead we have
1. StudentsV1Controller and
2. StudentsV2Controller
When a request is issued to the following URI, depending on the query string parameter "v" value we want to select the controller. If the value is 1, select StudentsV1Controller, and if it is 2, then select StudentsV2Controller.
/api/students?v=1
Step 1 : Since the default controller selector implementation provided by Web API does not work for us, we have to provide our own custom controller selector implementation. To do this
1. Add a folder to the web api project. Name it "Custom"
2. Add a class file to the folder. Name it "CustomControllerSelector".
For the "CustomControllerSelector" class code please check the link below
http://csharp-video-tutorials.blogspo...
Step 2 : The next thing that we need to do is, replace the default controller selector with our custom controller selector. This is done in WebApiConfig.cs file. Notice we are replacing IHttpControllerSelector, with our CustomControllerSelector. DefaultHttpControllerSelector implements IHttpControllerSelector, so that is the reason we replacing IHttpControllerSelector.
config.Services.Replace(typeof(IHttpControllerSelector),
new CustomControllerSelector(config));
Step 3 : Include the following default route in WebApiConfig.cs
config.Routes.MapHttpRoute(
name: "DefaultRoute",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Step 4 : Remove [Route] attribute, from action methods in StudentsV1Controller and StudentsV2Controller
Auf dieser Seite können Sie das Online-Video Web API versioning using querystring parameter mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer kudvenkat 28 Februar 2017 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 64,900 Mal angesehen und es wurde von 225 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!