【问题标题】:Application hangs when sending from MVC Web Application to Azure IoT Hub Device从 MVC Web 应用程序发送到 Azure IoT 中心设备时应用程序挂起
【发布时间】:2017-10-22 07:51:44
【问题描述】:

这是处理设备通知逻辑的 Azure Web 应用的控制器代码。我正在做的是从 ASP MVC 控制器调用下面显示的代码。但是当我运行它时,我会从浏览器中收到一个未决的请求(它挂起)。 我有一个按钮,当点击时,它会调用控制器中的唤醒方法。

代码与MSDN 上用于控制台应用程序的代码没有什么不同。我错过了什么?

using System.Text;
using Microsoft.Azure.Devices;

 public class MyTemplate2Controller : Controller
    {
        static ServiceClient serviceClient;
        static string connectionString = "HostName=azure-devices.net;SharedAccessKeyName=iothub;SharedAccessKey=mrUPt*2318C18K3LUk+oFarkNQ4vRvHrOa/eg=";

        private AsyncController Task SendCloudToDeviceMessageAsync()
        {
            var asd = "{13A20041677B0,4,15,0}";
            var commandMessage = new Message(Encoding.ASCII.GetBytes(asd));
          return  await serviceClient.SendAsync("Test_Comp_Dev_1", commandMessage).ConfigureAwait(continueOnCapturedContext: false);
        }
        public void Wakeup()
        {

            serviceClient = ServiceClient.CreateFromConnectionString(connectionString);

            SendCloudToDeviceMessageAsync().Wait();
        }

【问题讨论】:

标签: azure asp.net-mvc-4 azure-web-app-service iot azure-iot-hub


【解决方案1】:

尝试以下方法:

    public void Wakeup()
    {
        serviceClient = ServiceClient.CreateFromConnectionString(connectionString);

        System.Threading.ThreadPool.QueueUserWorkItem(a => SendCloudToDeviceMessageAsync().Wait());
    }

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-05-12
  • 2019-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多