- Prerequisites
- Creating the Project Structure
- Debugging the OnStart Method
- Connecting to the Platform
- Creating a Service
- Sending Requests to Another Service
- Posting Events when the Job is Submitted and Completed
- Subscribing to Service Events
- Sending REST Requests to Your Service
- Additional Resources
Prerequisites
Before proceeding with the tutorial, please install the following software:
- .NET Core 2.0
- IDE with .NET Core 2.0 support or just editor
- Oracle VM VirtualBox
- HashiCorp Vagrant
- Avid Platform Virtual Machine
For instructions on setting up VirtualBox, Vagrant, and the Avid Platform Virtual Machine, see the README included in the Avid Platform Virtual Machine download file (avid-platform-vagrant-vm-YYYY-MM-DD-XXXX.zip).
Creating the Project Structure
Create a new Windows Console Application project by selecting
File->New->Project...
.In the New Project dialog, navigate to
Templates->Visual C#->Windows
and select theConsole Application
template.Set the project name to NetService and click
OK
to create the project.In the Solution Explorer pane, rename the
Program.cs
file toNetServiceMain.cs
. Click Yes, when asked to perform a rename in the project of all references to the code elementProgram
.Add the following content to
NetServiceMain.cs
.Add the Avid-supplied
libs
folder as a NuGet repository as follows.- Select
Tools->NuGet Package Manager->Package Manager Settings
. - In the Options dialog that appears, choose Package Sources. In the Available Package Sources area of the dialog, click the plus button.
- Name it
Avid .NET
, and for theSource
value navigate to thelibs
folder (extracted from the avid-connector-api-net-XXXX.zip). - Click OK to perform the operation and close the Options window.
- Select
Add the avid-acs-proxybal-net package to solution as follows.
- Select
Project->Manage NuGet Packages...
. - Check the Include prerelease checkbox.
- Change the Package source to
Avid .NET
- Select the Browse option and search for avid-acs-proxybal-net.
- When the avid-acs-proxybal-net package appears in the results list, select the latest version (v2.2.1-build-XXXX at time of writing).
- Click the Install button.
- In the Preview dialog that appears, click OK to accept the changes.
- In the License Acceptance dialog that appears, click the I Accept button.
Note: If it becomes necessary to update a package, it is good practise to eliminate dependency issues by uninstalling all packages associated with a project prior to the update. To uninstall a package associated with a project, right-click the project in the Solution Explorer and select
Manage Nuget Packages for Solution...
from the popup menu.- Select
Close the package manager pane.
Select
Project->Add Reference...
. In the Reference Manager dialog that appears, browse the Assemblies Framework group and add a reference toSystem.Runtime.Serialization
assembly. Click the OK button to save your changes.Build the project using the “Rebuild Solution” option by selecting
Build->Rebuild Solution
. In the Output pane you should see output similar to the following:1
2
31>------ Rebuild All started: Project: net-service, Configuration: Debug Any CPU ------
1> net-service -> c:\users\name\documents\visual studio 2015\Projects\net-service\net-service\bin\Debug\net-service.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========Although it will currently not connect to the Avid Platform, you should build your project by clicking the
Start
button within Visual Studio.
Connecting to the Platform
- Create a
NetServiceBase.cs
file by right-clicking on theNetService
project in the Visual Studio Solution Explorer pane. From the pop-up menu, selectAdd->New Item...
. In the Add New Item dialog, select theVisual C# Class
solution item, give it the name NetServiceBase.cs, and click Add.
1 | using System; |
- Update the file
NetServiceMain.cs
to have the following content.
1 | using System; |
Build the project using the “Rebuild Solution” option by selecting
Build->Rebuild Solution
. In the Output pane you should see output similar to the following:1
2
31>------ Rebuild All started: Project: net-service, Configuration: Debug Any CPU ------
1> net-service -> c:\users\name\documents\visual studio 2015\Projects\net-service\net-service\bin\Debug\net-service.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========Start the service by selecting
Debug->Start Debugging
.
Congratulations! You have successfully connected to Avid Platform as a client.
Creating a Service
Create a
NetService.cs
file by right-clicking on thenet-service
project in the Visual Studio Solution Explorer pane. From the pop-up menu, selectAdd->New Item...
. In the Add New Item dialog, select theVisual C# Class
solution item, give it the name NetService.cs, and click Add.Add following content to the
NetService.cs
file:
1 | using Avid.Platform.Bus.Messaging; |
- Modify the
NetServiceBase.cs
file as follows:
1 | using Avid.Platform.Bus; |
Add a folder named
Resources
to your project.Right-click on the
Resources
folder and selectAdd->New Item...
from the pop-up menu. Select Resources File from the Add New Item dialog, give it the nameExamples.resx
, and click the Add button.Open
Examples.resx
.Change the Access Modifier for the resources file to No code generation.
Add following string resources to this file: (If when entering the example resouce you get an
invalid identifier
error, right-click onExamples.resx->Properties
and clear the value for the fieldCustom Tool
)Name Value submitJob.Submit_invalid_execTime { “jobId”: 2, “execTime”: 10 } submitJob.Submit_invalid_jobId { “jobId”: -1, “execTime”: 1000 } submitJob.Submit_valid_job { “jobId”: 1, “execTime”: 1000 } Build the project using the “Rebuild Solution” option by selecting
Build->Rebuild Solution
.Start the service by selecting
Debug->Start Debugging
.Test the service to verify it is working:
- Open the ACS Monitor, and filter the services list by providing
net\.service
regular expression in the box. You should now see now only one service in the list:avid.tutorial.net.service
- Expand operations list, the operations list, using the small leftmost icon under the service name. You should see a
submitJob
operation there. - Click on
Submit valid job
link. You should see a message generated on the right-hand side, in theRequest
field. - Click
Query
button. You should get a response back from your service in theResponse
field.
- Open the ACS Monitor, and filter the services list by providing
Stop the NetService.
Congratulations! You have successfully registered your service on the Platform.
Sending Requests to Another Service
- Create the file
NetServiceResponse.cs
with the following contents:
1 | using System; |
- In this step you modify the
SubmitJob
method in theNetService.cs
file. You add a constructor and two new methods,SetNumberOfSubmittedJobs
andGetNumberOfSubmittedJobs
, to update and request the number of submitted jobs. In addition, you add methods and interfaces to handle asynchronous requests:
1 | using Avid.Platform.Bus; |
- Next, modify the contents of the
NetServiceBase.cs
file, to pass a BusAccess to constructor:
1 | using Avid.Platform.Bus; |
Build the project using the “Rebuild Solution” option by selecting
Build->Rebuild Solution
.Start the NetService service by clicking
Debug->Start
.Test the service in the ACS Monitor. Send several
submitJob
requests to your service. With each request you should see the number of submitted jobs increment in the response:1
2
3
4
5
6{
"resultSet": {
"jobStatus": "submitted",
"numberOfSubmittedJobs": 2
}
}Stop the NetService service.
Congratulations! You have successfully sent a request to another service, and received a response from it.
Posting Events When the Job is Submitted and Completed
- Edit the
NetService.cs
file:
1 | using Avid.Platform.Bus; |
Build the project using the “Rebuild Solution” option by selecting
Build->Rebuild Solution
.Start the NetService service by clicking
Debug->Start
.Test the service in the ACS Monitor.
Stop the NetService service.
Congratulations! You have successfully published events to the Platform.
At this point the service behavior in the ACS Monitor is unchanged. Next, we create a consumer of our service events.
Subscribing to Service Events
Other services and clients may wish to listen on the channel to which our service posts, so they can receive event information. We demonstrate this functionality by creating a new client that listens on the channel.
Create a new Console Application project by right-clicking on the solution and selecting
Add->New Project...
from the pop-up menu. SelectC#->Windows->Classic Desktop->Console Application
, giving it the nameNetClient
. Click the OK button to save your changes.Add the avid-acs-proxybal-net package to the NetClient project as follows.
- Select the NetClient project in the Solution Explorer.
- Select
Project->Manage NuGet Packages...
. - Check the Include Prerelease checkbox (if not already done)
- Select the Browse option and search for avid-acs-proxybal-net.
- When the avid-acs-proxybal-net package appears in the results list, select the latest version (v2.2.1-build-XXXX at time of writing).
- Click the Install button.
- In the Preview dialog that appears, click OK to accept the changes.
- In the License Acceptance dialog that appears, click the I Accept button.
Rename Program.cs
to
NetClient.cs` and add the following content to the file:
1 | using Avid.Platform.Bus; |
Build the project using the “Rebuild Solution” option by selecting
Build->Rebuild Solution
.Setup the solution to start both service and client at the same time by right clicking on
Solution->Properties->Startup Project->Multiple Startup Projects
. Ensure that the value of bothNetClient
andNetService
areStart
.Run both project with
Debug->Start
.Test the service to verify it is working:
- Open the ACS Monitor, and filter the services list by providing
net\.service
regular expression in the box. You should now see now only one service in the list:avid.tutorial.net.service
- Send multiple
submitJob
messages to your service with different values. Examine the logs of your client. The logs ought to contain each “job submit” and “job complete” event.
- Open the ACS Monitor, and filter the services list by providing
Congratulations! You have created a client that subscribes to the events being posted by your service.
Sending REST Requests to Your Service
- Log in to
avid-platform-zone1
with ssh (username: root; password: vagrant):
1 | ssh root@avid-platform-zone1 |
- Send POST requests to your service using the
curl
command, use the avidAccessToken generated previously:
1 | curl -H "Content-Type: application/json" --data '{"execTime":15000}' "http://avid-platform-zone1:8000/apis/avid.tutorial.net.service;version=1/jobs/10?_avidAccessToken=ZWEwZDhlOTItYmJhZS00YTQ5LWFiN2QtNTAyYWMwZjhjZjJj" |
Given HTTP request will send following message to your service:
1 | { |
- Stop the service and press
ESC
in the shell to terminate the client.
Congratulations! You have completed this tutorial.
Additional Resources
For more details on the .NET API please refer to the Microsoft documentation: