How to Build and Run the Billing Adapter Sample

 

Applies To: Windows Azure Pack

The billing adapter sample is provided as part of the Windows Azure Pack Developer Kit samples available at https://www.microsoft.com/en-us/download/details.aspx?id=41146. The following topic demonstrates how to build and run the sample either as a console application or as a Windows Service. A script is also provided showing how to run the sample as a Windows Service.

Note

When the Billing Adapter is first started, it may take a while to consume all the historical data in the Windows Azure Pack Usage API. If there are many events to consume, the tenant features should be temporarily disabled to avoid any synchronization issues. If this is not done, users may have some of their purchasing operations blocked if the dependent events have not been processed into the billing system at the time of purchase. This can be done by stopping the application pools or site services of the TenantSite, TenantAPI, and TenantPublicAPI.

Building the Billing Adapter Sample

To build the Billing Adapter Sample

  1. Extract the Windows Azure Pack developer kit zip file to a folder.

  2. In the extracted folder, locate the Billing Adapter Visual Studio solution Microsoft.WindowsAzurePack.Samples.Billing.sln in the BillingAdapter folder.

  3. Open the solution (.sln) file in Visual Studio.

  4. Ensure the latest NuGet Package Installer is installed by selecting the Tools menu option and then Extensions and Updates. In the displayed dialog box, select Online and then Visual Studio Gallery to see if there is an update to the NuGet Package Manager. If there is, install it.

    If the NuGet Package Manager is not installed, see https://www.nuget.org/.

  5. Open the NuGet Package installer options dialog box to ensure required packages are automatically downloaded. Do this by selecting the Tools menu, Library Package Manager, Manage Nuget Packages for Solution…. The Manage NuGet Packages dialog box will be displayed. Click Settings to open the Options Dialog box.

  6. Select Package Manager and then General.

  7. In the Package Restore section, ensure Allow Nuget to download missing packages and Automatically check for missing packages during build in Visual Studio are checked.

  8. Click OK to close the settings dialog and then click Close to close the Manage NuGet Packages dialog box.

  9. Build the solution in Visual Studio.

Running the Billing Adapter Sample

The Billing adapter sample can be run as either a console application or as a Windows Service.

It is recommended that you copy the build output directory (usually under bin\Debug or bin\Release in your project folder) to a different location and edit the app.config in this location according to your production environment settings. Copying the build outputs to a different location will prevent future builds from overwriting your app.config changes. Also make sure that your billing adapter system specific assembly is located in the same folder, including all its dependencies (or registered in the Global Assembly Cache). For more information about the app.config file, see About the Billing Adapter Core Engine Sample Files.

The billing adapter emits tracing messages to a Windows Event Log channel. This channel must be registered before it can be used. To register the channel, invoke the billing adapter executable with the registerlog argument. For example Microsoft.WindowsAzurePack.Samples.Billing.exe registerlog.

To Run the Billing Adapter as a Console Application

  1. Open a Command Prompt

  2. Run Microsoft.WindowsAzurePack.Samples.Billing.exe with the registerlog argument from the output folder (usually under bin\Debug or bin\Release in your project folder).

To Run the Billing Adapter as a Windows Service

  1. Open a Command Prompt.

  2. Run Microsoft.WindowsAzurePack.Samples.Billing.exe with the registerlog parameter.

  3. On the billing adapter folder, grant Read & Execute permissions to the account that will be used to run the service.

  4. Register the billing adapter as a Windows service. When registering the billing adapter executable as a Windows service, it is necessary to provide the "service" argument: Microsoft.WindowsAzurePack.Samples.Billing.exe service.

  5. Start the Windows Service.

Script to Run the Billing Adapter Sample as a Windows Service

The following script demonstrates how to run the Billing Adapter Sample as a Windows Service

# \"Install\" the billing adapter (creates the event log channel where the service will log events)
<Path to Sample Build Location>\Microsoft.WindowsAzurePack.Samples.Billing.exe registerlog

# Give permissions to the account running the service to access the folder where it is installed and run the executable
icacls <Path to Sample Build Location>/T /grant "NT AUTHORITY\NETWORK SERVICE:(RX)"

# Create (register) the service to be run on startup using the account given access above.
sc create wapbill start= auto binPath= "<Path to Sample Build Location>\Microsoft.WindowsAzurePack.Samples.Billing.exe service" obj= "NT AUTHORITY\NetworkService" DisplayName= "Azure Pack Billing Adapter"

# start the service
sc start wapbill

See Also

About the Billing Adapter Core Engine Sample Files
The Windows Azure Pack Billing Adapter Sample