This demo project shows a very simple ASP.NET Web API service that returns hello world. It is secured with XSUAA from SAP BTP and can be deployed via mta.yaml
to SAP BTP Cloud Foundry Environment.
It can be used as a template to build more complex multi-target that require a .NET module.
There is no standard NuGet package available (e.g. @sap/xssec
for CAP NodeJS) to easily connect to the defined security configuration in xs-security.json
, so this has to be done manually in the project.
Have a look in the Authentication folder to see how this can be done.
❗ The implementation is reverse engineered from @sap/xssec. Use at your own risk 😄 ❗ |
---|
Logging in JSON format is enabled via the Serilog library and active in productive environment.
For the logger property logger
the triggering class name of the log event is used. The correlation_id
is either taken from the request header x-correlation-id
(e.g. if passed from another cf application) or a new UUID is created which will be added to each log message, that is created during a single request.
The project also contains a small CAP project to demonstrate the proper forwarding of the correlation_id
when the .NET endpoint is called from CAP (see proxy-service.js).
A workaround for the builder is required, as dotnet_core
is no longer a recognized and valid application type.
In this sample we use the nodejs
module type and overwrite the builder with a dummy echo
command. As we use a source-based deployment, no build for the .NET module is required.
The actual build will be done via the buildpack during the set-up of the container.
modules:
- name: my-dotnet-service-module
type: nodejs
path: <path-to-folder-with-.net-solution>
build-parameters:
builder: custom
commands:
- echo ">> Building .NET module"
...
Additionally, the online build pack for .NET has been removed in Nov 16, 2023 (SAP note 3364781), so we need to specify a valid one in the parameters
section of the module.
The repository dotnet-core-buildpack in the Cloud Foundry org holds different releases. If you require a certain stack (i.e. concrete .NET Core version) you can use a specific release by adding the release tag after the repository url.
...
parameters:
buildpack: https://github.com/cloudfoundry/dotnet-core-buildpack.git#v2.4.27
To define certain options for the used buildpack we need to create an additional file called buildpack.yml
in the root path of the .NET module.
Here we can set the .NET version to be used:
---
dotnet-core:
sdk: 8.0
If you have several projects in your module you need to specify your main project in a file .deployment
at root level of the .NET module:
[config]
project = src/DemoService/DemoService.csproj
mbt build --mtar archive
# login to cloud foundry and choose space for deployment
# cf l
cf deploy mta_archives/archive.mtar
Create .env
file in folder /test
, to execute the requests in api-test.http.
# Credentials of XSUAA instance
uaaUrl=https://...
clientId=
clientSecret=""
# URLS of deployed CAP and .NET modules
appUrl=https://...
capAppUrl=https://..
user_default_idp=
pw_default_idp=""
# If you have a custom IdP configured
user_custom_idp=
pw_custom_idp=""