In this 1st article I’m going to use a lot of scaffolding code from Microsoft to get up and running very quickly. I’m going to create a Web Site application (based upon MVC) and a separate Web API Application. I’m going to keep them in a single solution for now just to even further simplify the learning curve. They may break out at a late stage once we start to consider automated testing techniques.

I’m going to use Visual Studio (and 2019 version in particular) and use .NET Core 2.2. I’ll hopefully migrate to .NET Core 3.0 as soon as possible after release. However there is no reason why these can’t be created using the .NET Core command line tools and I’ll link to relevant articles showing how to do this at the end of this post. I’m also not aware of anything here that is specifically .NET Core 2.2 specific, so things may be okay with earlier versions (but please let me know if you find anything and I’ll amend).

The Web Application

At this stage I’m not sure what role this Web Application is going to fulfill in the ecosystem so I intend to use the very scaffold default MVC website project from Microsoft. This should allow flexibility going forward, or alternatively it may get fully replaced in the future. For now it’s sole purpose to display data from the other microservices that will be introduced.

1. Start Visual Studio and select ‘Create New Project’.
2. Select ‘ASP.NET Core Web Application’ and click ‘Next’.

createnewproject1-2

3. Select a suitable name (I’ve got for ViewerWebApplication) and I’ve place it under a folder called UniversityExample.
4. Then select Web Application (Model-View-Controller) and click Create.

createnewproject1-4

Once Visual Studio has created the application, hit F5 (or the Green play button with IIS Express) and check that the website runs. It should look similar to below:

createnewproject1-5

We’ll explore some of the code that has been generated as we start to bring in new functionality later in the series.

The Web API Application

Next. in the same solution, we’re going to add the out-the-box Web API application.

1. Right click on the solution and click ‘Add’ and ‘New Project’.
2. Again select ASP.NET Core Web Application and click Next.
3. For project name, call it ‘StudentRecordSystem’ and click Create.
4. On the next screen click ‘API’ and then click ‘Create’.

When launching applications, Visual Studio will launch them on random ports. In order to fix this, for the Web API application just created, expand ‘Properties’ and click on the ‘launchSettings.json’ file. Change the bottom section to specify a port for the https:// address and remove the http:// entry altogether. Your new file should look similar to the following:

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://localhost:62421",
      "sslPort": 44382
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "StudentRecordSystem": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "applicationUrl": "https://localhost:5100",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

Finally, rather than using Visual Studio to run this app, we’ll use the command line to it. Right click on the project ‘StudentRecordSystem’ and find the entry ‘Open Folder in File Explorer’. Once Windows Explorer opens, in the address bar, type cmd and press enter. This will launch a command line window at the directory specified.

On the command line type ‘dotnet run’ and wait for some output telling you the app is running, similar to below:

createnewproject2-1

Now head to a browser, and enter the address above, e.g. https://localhost:5001/api/Values and you should get the following output:

createnewproject2-2

Don’t worry about any security certificate warnings just for now.

Nothing too exciting just yet, but next we’ll look to introduce a new API controller which will provide some hardcoded student information, which we’ll then display on the Web Site application, creating a connection between the 2 applications.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s