IBM Cloud Functions Adds Support for .NET Core 2.2

By: Carlos Santana

What’s happening with IBM Cloud Functions and .NET Core?

I’m excited to announce that IBM Cloud Functions officially supports .NET Core 2.2 natively. Now, you can join the serverless revolution and start building cloud-native apps without worrying about scaling or infrastructure management by using Functions as a Service.

Ready to try it out?

  1. Create a C# project called `Example.`

    dotnet new classlib -n Example -lang "C#"
    cd Example/
  2. Install the Newtonsoft.Json NuGet package.

    dotnet add package Newtonsoft.Json -v 12.0.1
  3. Edit the Example/Class1.cs file.

    using System;
    using Newtonsoft.Json.Linq;namespace Example
    {
    public class Hello
    {
    public JObject Main(JObject args)
    {
    string name = "IBM Cloud";
    if (args.ContainsKey("name")) {
    name = args["name"].ToString();
    }
    JObject message = new JObject();
    message.Add("greeting", new JValue($"Hello, {name}!"));
    return (message);
    }
    }
    }
  4. Compile the code.

    dotnet publish -c Release -o out
  5. Create a .zip of the out directory.

    cd out
    zip -r -0 ../helloDotNet.zip *
    cd ..
  6. Create a web action with the IBM Cloud Functions CLI plugin by running the following command.

    ibmcloud fn action update helloDotNet helloDotNet.zip --main Example::Example.Hello::Main --kind dotnet:2.2 --web true
  7. Get the URL for the web action by running the following command.

    ibmcloud fn action get helloDotNet --url
  8. Open the URL in your browser.

How fast are .NET Core Functions?

Actions using the .NET Core runtime are very performant with an overhead similar to the fast Node.js runtime.

Here is a chart that compares the latency of a hello world Action in .NET vs. Node.js.

How fast are .NET Core Functions?

How do I learn more?

To see how easy it is to set up a project and compile your .NET Core Actions, check out the documentation.

Be the first to hear about news, product updates, and innovation from IBM Cloud