Hello @MRezaNaeemabadi-5529,
without the exception you get, it's a bit hard to figure out what is happening.
The code you added to the HttpTrigger function seems quite ok. Here are some points of attention.
First, the name of the direct method is case-sensitive.
Next, Did you reference the Nuget package Microsoft.Azure.Devices so the code knows what a Service Client is?
You can try to add it in the portal (like this) but I recommend creating a function property in Visual Studio or VS Code.
This way it far easier to add a package, to debug, etc.
Finally, Check the response of the direct method like:
var response = await _serviceClient.InvokeDeviceMethodAsync(deviceId, moduleId, requestMethod);
directMethodResponse.ResponseStatus = response.Status;
if (directMethodResponse.ResponseStatus == 200)
{
var jsonResponse = response.GetPayloadAsJson();
if (!string.IsNullOrEmpty(jsonResponse))
{
directMethodResponse.DeserializePayload(jsonResponse);
return directMethodResponse;
}
}