我创建了一个web应用程序,然后写了一函数用于从Cloud发送消息给Device,如下所示。
在web应用的Application_Start中调用此函数,模拟设备能够收到消息。
但是在Controller中调用此函数,模拟设备就收不到消息。这是什么原因?
private async Task SendCloudToDeviceMessageAsync()
{
string connectionString = "HostName=ttt.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=benJRoV7sHebFxwKvAg1Y7m4gI9Hcsp2DBaEQ2j/+Oo=";
ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(connectionString);
var commandMessage = new Message(Encoding.ASCII.GetBytes("Cloud to device message."));
serviceClient.SendAsync("mySecondDevice", commandMessage);
}