/// <summary> /// Call method with json payload. /// </summary> /// <param name="client"></param> /// <param name="deviceId"></param> /// <param name="moduleId"></param> /// <param name="method"></param> /// <param name="json"></param> /// <param name="timeout"></param> /// <param name="ct"></param> /// <returns></returns> public static async Task <string> CallMethodAsync(this IMethodClient client, string deviceId, string moduleId, string method, string json, TimeSpan?timeout = null, CancellationToken ct = default) { var response = await client.CallMethodAsync(deviceId, moduleId, method, json == null?null : Encoding.UTF8.GetBytes(json), ContentMimeType.Json, timeout, ct); return(response.Length == 0 ? null : Encoding.UTF8.GetString(response)); }
/// <summary> /// Call method with json payload. /// </summary> /// <param name="client"></param> /// <param name="deviceId"></param> /// <param name="moduleId"></param> /// <param name="method"></param> /// <param name="json"></param> /// <param name="timeout"></param> /// <returns></returns> public static async Task <string> CallMethodAsync(this IMethodClient client, string deviceId, string moduleId, string method, string json, TimeSpan?timeout = null) { var response = await client.CallMethodAsync(deviceId, moduleId, method, Encoding.UTF8.GetBytes(json), ContentEncodings.MimeTypeUaJson, timeout); return(Encoding.UTF8.GetString(response)); }