public async Task <CloudToDeviceMethodResult> SendMethod(string deviceId, string command, string payload)
        {
            JObject cmdPayload = JObject.Parse(payload);

            if (_serviceClient != null)
            {
                var methodInvocation = new CloudToDeviceMethod(command)
                {
                    ResponseTimeout = TimeSpan.FromSeconds(30)
                };

                Twin deviceTwin = await GetDeviceTwin(deviceId);

                if (!string.IsNullOrEmpty(deviceTwin.ModelId))
                {
                    DTDLModelResolver resolver = new DTDLModelResolver(_privateModelRepoUrl, _privateModelToken, _logger);

                    var modelData = await resolver.ParseModelAsync(deviceTwin.ModelId);

                    var interfaces = modelData.Where(r => r.Value.EntityKind == DTEntityKind.Command).ToList();

                    //var commands = interfaces.Select(r => r.Value as DTCommandInfo).Where(x => x.Name == command).ToList();
                    var dtCmd = interfaces.Select(r => r.Value as DTCommandInfo).Single(x => x.Name == command);

                    if (cmdPayload.ContainsKey(dtCmd.Request.Name))
                    {
                        switch (dtCmd.Request.Schema.EntityKind)
                        {
                        case DTEntityKind.String:
                            methodInvocation.SetPayloadJson(new string(cmdPayload[dtCmd.Request.Name].ToString()));
                            break;

                        case DTEntityKind.Integer:
                            if (cmdPayload[dtCmd.Request.Name].Type == JTokenType.String)
                            {
                                var value = cmdPayload[dtCmd.Request.Name].ToString();

                                // convert to integer
                                Regex rx = new Regex(@"^[0-9]+$");

                                if (!rx.IsMatch(value))
                                {
                                    var result = new CloudToDeviceMethodResult()
                                    {
                                        Status = 400,
                                    };
                                    return(result);
                                }
                                else
                                {
                                    methodInvocation.SetPayloadJson(Int32.Parse(value).ToString());
                                }
                            }
                            break;

                        case DTEntityKind.Float:
                        case DTEntityKind.Double:
                            break;
                        }
                        //cmdPayload.
                    }
                }

                try
                {
                    var response = await _serviceClient.InvokeDeviceMethodAsync(deviceId, methodInvocation);

                    Console.WriteLine("Response status: {0}, payload:", response.Status);
                    Console.WriteLine(response.GetPayloadAsJson());
                    return(response);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Exception in GetIoTHubDevice() : {e.Message}");
                }
            }
            return(null);
        }