【发布时间】: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();
}
【问题讨论】:
-
这个问题太笼统了,我建议你尝试做一个远程调试会话,看看你的代码到底哪里出错了。 docs.microsoft.com/en-us/visualstudio/debugger/…
标签: azure asp.net-mvc-4 azure-web-app-service iot azure-iot-hub