locked
Azure IoT Edge Gateway Serivce RRS feed

  • Question

  • I've been working with the Azure IoT Edge Gateway SDK for a few days now and created a few custom .NET modules to process edge device data.  One thing I can not figure out is how to run the Gateway as a windows service.  When I compile the project I get the module dll's and the gateway runtime (gw.exe) in the output folder.  I can run the gw.exe from the command like ok but I I would want the gateway to run all the time on machine startup.  Installing the gateway as a windows service seems like the way I would want go.

    Is there something that I'm missing or not understanding about how the gaterway sdk is suppose to work?

    Tuesday, June 6, 2017 5:02 PM

All replies

  • Hi Scott,

    There is a way that you can make a gateway to run as a service.

    When you use gw.exe, you are using a sample of our native gateway (Example code here: https://github.com/Azure/iot-edge/blob/master/samples/dotnet_binding_sample/src/main.c) .

    If you want to run gateway as a service you need to create a service compatible gateway.

    I believe most people prefers to create a Service using .NET, if it's your scenario you can do the following:

    1-Create your Service App on Visual Studio;

    2-Wrap our native gateway calls (For exemple, Create a GatewayWrapper.cs file on your project with the following code:

    namespace DotNetCoreManagedGateway
    {
        class GatewayWrapper
        {
            [DllImport(
                "gateway.dll",
                CharSet = CharSet.Ansi,
                EntryPoint = "Gateway_CreateFromJson",
                CallingConvention = CallingConvention.Cdecl
            )]
            public static extern IntPtr CreateFromJson(string file_path);

            [DllImport(
                "gateway.dll",
                EntryPoint = "Gateway_Destroy",
                CallingConvention = CallingConvention.Cdecl
            )]
            public static extern void Destroy(IntPtr gateway);
        }
    }

    3-Than you can create your gateway like this:

        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    if (args.Length < 1 || File.Exists(args[0]) == false)
                    {
                        Console.Error.WriteLine("Usage: managed-gateway <<path to json>>");
                    }
                    else
                    {
                        var json_path = args[0];
                        var gateway = GatewayWrapper.CreateFromJson(json_path);


                        Console.WriteLine(".NET Core Gateway is running. Press return to quit.");
                        Console.ReadLine();

                        GatewayWrapper.Destroy(gateway);
                    }
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine($"ERROR: {ex.ToString()}");
                }

    Hope this helps,

    Let me know,

    Angelo Ribeiro.

    Wednesday, June 7, 2017 6:10 PM