Note: This topic applies to the Web API presentation project type only. Refer to Creating a RESTful Web Service Application for more information.
Scaffolding is the technique used to generate the presentation code that the application can use at run time. The generated code represents a useful starting point for your application that you may want to further modify to refine the application.
Refer to the following topics for more information:
To scaffold one or more data sources in your presentation project, do the following:
Click Build and select Build Solution to build the solution.
In Solution Explorer, navigate to a Web API project. If you are using areas, navigate to the correct area folder (for example Areas/<areaname>, where <areaname> is the name of your area).
Note: An Area is a logical grouping of Controller, Models, and other related folders in a Web API application. Areas are an optional feature in Web API. For an example, refer to https://msdn.microsoft.com/en-us/library/ee671793(v=vs.100).aspx.
Right-click the project or area folder and select Add, then select New Scaffolded Item.
The Add Scaffold dialog opens.
On the Add Scaffold dialog, select Unisys Web API Controller for ePortal Data Source and click Add.
The Scaffold Unisys Web API Controller for ePortal Data Source Dialog opens.
Complete the dialog as described below.
After completing the dialog fields, click OK to start scaffolding.
Note: If scaffolding would overwrite any existing files, you are given a chance to confirm before overwriting.
Dialog Fields
The dialog fields are described below:
ePortal Data Source
Select the name of the data source to scaffold from the dropdown list.
Note: If you do not see the data source project you are looking for, ensure that the data source project is opened in the current solution and a reference has been added. Refer to Using Multiple Data Source Projects for more information.
Controller name
Specify a name for the controller. This name is used as follows:
The name of the controller class is formed by appending "Controller" to the name you specify.
A file named <controllername>Controller.cs is created in the Controllers folder, where <controllername> is the controller name that you specify.
The URL to reference this controller for convention-based routing at run time is of the form http://<host>:<port>/ep/<controllername>, where <host> is the IP address or DNS name of the server hosting your application (for example, localhost for local testing), <port> is the port number for the web server, and <controllername> is the controller name that you specify. Refer to Testing a Web API RESTful Web Service Application for more information.
For attribute-based routing, <controllername> is not used.
Controller scaffolder
Select the scaffold template to use to generate the controller code from the list. The dropdown displays the scaffolders present in the CodeTemplates/AddController directory.
Notes:
For compatibility with previous versions of ePortal, select Unisys Web API Controller for ePortal Data Source as Controller Scaffolder.
To make use of the enhanced routing options, select Unisys Data Source Web API Controller Version 2 as Controller Scaffolder.
Refer to Scaffold Templates and Creating Custom Scaffold Templates for more information.
Route Prefix
Specify the RoutePrefix to apply to all routes using attribute routing.
This property works in conjunction with the Route property. When specified, the [RoutePrefix(“<routePrefix>”)] attribute is applied to the controller class.
Refer to REST Route Collection Editor for more information on the route rules that the prefix must conform to.
Entire application requires HTTPS
Specify if HTTPS is required for the application.
When this option is selected, the scaffolder adds the [HTTPS] attribute to the controller class.
Session required
If the web service requires a session (that is, is a stateful application), select this option.
Set Swagger as debug start page
Configure the project to use Swagger as the default start page, if not already configured.
Verb
Specify the verb to use for the connect or disconnect web methods (under Connect and Disconnect).
These options are disabled when the Session required check box is clear.
Action Name
Specify the ActionName to use for the connect or disconnect methods (under Connect or Disconnect) when convention-based routing is used.
These options are disabled when the Session required check box is clear.
Route
Specify the route to use for the connect or disconnect methods (under Connect or Disconnect) when attribute based routing is used.
These options are disabled when the Session required check box is clear.
Web Method Return
Scaffolded web methods have a return type of System.Web.Http.IHttpActionResult which allows explicit return of HTTP Response Codes.
Response codes returned include OK (200), Bad Request (400), Internal Server Error (500), and Not Implemented (501).
Each web method includes the following method attributes:
[SwaggerResponse(HttpStatusCode.BadRequest, Type=typeof(Unisys.Error))]
[SwaggerResponse(HttpStatusCode.OK, Type=typeof(Unisys.Message))]
- if no specific message is specified in orchestration
Or
[SwaggerResponse(HttpStatusCode.OK, Type=typeof(<SpecificMessage>))]
- where <SpecificMessage> is the Client Message specified as the only return in orchestration.
Other response codes, if returned, do not contain predefined response type.
Verbs
When scaffolding for the Verb is “Delete”, the method returns a result of NotImplemented (code 501) with no data. You can modify or override the method to perform the desired action, if required.
Attribute Routing
If attribute routing is used with parameters embedded in the URI, the parameters are matched by name and applied to the model for the matched results. Additionally, the parameter attribute [FromUri] is added to the parameter list.
Extending the Controller
Refer to Programming in the Controller for MVC Web for more information on extending the Controller.