WoT.Net.Binding.Http 0.0.2

dotnet add package WoT.Net.Binding.Http --version 0.0.2
                    
NuGet\Install-Package WoT.Net.Binding.Http -Version 0.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WoT.Net.Binding.Http" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WoT.Net.Binding.Http" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="WoT.Net.Binding.Http" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WoT.Net.Binding.Http --version 0.0.2
                    
#r "nuget: WoT.Net.Binding.Http, 0.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=WoT.Net.Binding.Http&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=WoT.Net.Binding.Http&version=0.0.2
                    
Install as a Cake Tool

WoT.Net.Binding.Http

NuGet Version

A .NET Standard 2.0 implementation of the W3C Web of Things (WoT) Scripting API, inspired by node-wot

What is the W3C Web of Things (WoT)?

The W3C Web of Things is a standardization effort that aims to facilitate the interoperability between the highly fragmented IoT technologies. Instead of imposing new technologies, WoT aims to provide a standardized model for modeling and describing the capabilities and the network/web interface that any IoT entity is providing. In the context of WoT, the capabilities of any entity are modeled as one of three interaction affordances:

  • Property Affordances: representing data sources or sinks that can be read or written to.
  • Action Affordances: representing operations that usually take longer or may physically affect the environment.
  • Event Affordances: representing any notifications or streams and the means to subscribe to them.

Each entity is then capable of describing its own WoT interface using a standardized description format called the Thing Description (TD), a JSON-LD document that is both highly human- and machine-readable and contains the entity's WoT model and any additional related metadata.

What is our aim?

Our long-term goal here is to provide the .NET Standard 2.0 stack that fully implements the Scripting API, which would facilitate rapid development of WoT applications, as well as also facilitating the integration of the WoT stack in Unity. Our short-term goal is to implement the functionalities of a WoT Consumer, i.e. the functionalities needed to fetch a TD and consume it to interact with the entity it describes. We will focus first on HTTP/S Things but aim to implement functionality for CoAP, CoAPS, and MQTT in the future.

What does this library provide?

This library offers an HTTP/S binding for the WoT.Net.Core package, allowing Consumers to interact with Things that expose their WoT interface over HTTP/S.

Installation

You can install the library via NuGet Package Manager Console by running the following command:

Install-Package WoT.Net.Http

or by using the .NET CLI:

dotnet add package WoT.Net.Http

Getting Started

Installing this package automatically install WoT.Net.Core as a dependency.

Here is a simple example showing how to use this library to consume a Thing Description (TD) and interact with the entity it describes using the HTTP/S protocol binding. This example shows how to read properties, invoke actions, and subscribe to events of a Thing Description that is hosted at http://plugfest.thingweb.io:80/http-data-schema-thing/.

using WoT.Core.Implementation;
using WoT.Binding.Http;
using WoT.Core.Definitions.TD;
using Newtonsoft.Json;


Consumer consumer = new();
HttpClientConfig clientConfig = new()
{
    AllowSelfSigned = true
};
consumer.AddClientFactory(new HttpClientFactory(new HttpClientConfig()));
consumer.AddClientFactory(new HttpsClientFactory(clientConfig));

consumer.Start();

ThingDescription td = await consumer.RequestThingDescription("http://plugfest.thingweb.io:80/http-data-schema-thing/");
ConsumedThing consumedThing = (ConsumedThing)consumer.Consume(td);

// Read a boolean
bool boolean = await (await consumedThing.ReadProperty<bool>("bool")).Value();
Console.WriteLine("Read a boolean: " + boolean);
// Read an integer
int integer = await (await consumedThing.ReadProperty<int>("int")).Value();
Console.WriteLine("Read an integer: " + integer);
// Read a number
float number = await (await consumedThing.ReadProperty<float>("num")).Value();
Console.WriteLine("Read a number: " + number);
// Read a string
string str = await (await consumedThing.ReadProperty<string>("string")).Value();
Console.WriteLine("Read a string: " + str);
// Read an array
object[] array = await (await consumedThing.ReadProperty<object[]>("array")).Value();
Console.WriteLine("Read an array: " + JsonConvert.SerializeObject(array));
// Read an object
Dictionary<string, object> obj = await (await consumedThing.ReadProperty<Dictionary<string, object>>("object")).Value();
Console.WriteLine("Read an object: " + JsonConvert.SerializeObject(obj));


// Invoke Action with no input and no output
await consumedThing.InvokeAction("void-void");

// Invoke Action with an input and no output
await consumedThing.InvokeAction("int-void", 1);

// Invoke Action with no input but an output
var outputBuffer = await (await consumedThing.InvokeAction<int>("void-int")).ArrayBuffer();
// Buffer to string
string outputJson = System.Text.Encoding.UTF8.GetString(outputBuffer);
// Deserialize JSON
int output = JsonConvert.DeserializeObject<int>(outputJson);
Console.WriteLine("Output of 'void-int' action was: " + output);

// Invoke Action with an input and an output
int output2 = await (await consumedThing.InvokeAction<int, int>("int-int", 4)).Value();
Console.WriteLine("Output of 'void-int' action was: " + output2);

if (consumedThing != null)
{

    // Subscribe to Event
    var sub = await consumedThing.SubscribeEvent<int>("on-int", async (output) =>
    {
        Console.WriteLine("Event: Received on-int event");
        Console.WriteLine($"Value received: {await output.Value()}");
        Console.WriteLine("---------------------");
    });

    var task = Task.Run(async () =>
    {
        while (sub.Active)
        {
            // Get random integer between 0 and 100
            Random random = new();
            int randomInt = random.Next(0, 100);
            Console.WriteLine($"Writing int {randomInt}");
            Console.WriteLine("---------------------");
            // Write an int
            await consumedThing.WriteProperty("int", randomInt);
            
            await Task.Delay(TimeSpan.FromSeconds(1));
        }
        return;
    });

    Task stopTask = Task.Delay(TimeSpan.FromSeconds(10)).ContinueWith(async (task) => { await sub.Stop(); });
    await task;
}
Console.WriteLine("Done");

For a more detailed step-by-step explanation and documentation, feel free to visit our documentation page.

Protocol Bindings

The library provides a way to extend the consumer implementation by adding different protocol bindings. This can be done by implementing the IClient and IClientFactory interfaces, described in the WoT.Core.Definitions.Client namespace.

Roadmap

  • TD Deserializing and Parsing
  • HTTP Consumer
  • HTTPS Consumer
  • CoAP Consumer
  • CoAPS Consumer
  • MQTT Consumer

... more in the future

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.2 202 3/6/2025