I got error in ASP.net core MVC and Azure iot hub

I got error in ASP.net core MVC and Azure iot hub



I`m Novice
Now I try to use ASp.net core to get some in Azure iot hub with this tutorial:https://ztirom.at/2016/03/frist-steps-azure-iot-hub/
but when I got a some error



enter image description here



What is something wrong happen?
how can I fix it or Another way to get some data from iot hub.
thank you everyone



this is my iothubconnectionstring part





The link you provided is about .net framework. It is different from asp.net core, you could refer to this article.
– Joey Cai
Aug 27 at 6:29





Hi Sunday, exception happens at regManager.GetDevicesAsync(), right? So you can create device(regManager.AddDeviceAsync) successfully?
– Rita Han - MSFT
Aug 27 at 7:33





@JoeyCai oh Thank you I will try that
– Sunday
Aug 27 at 8:13





@RitaHan-MSFT thank you but i tried but it cant to connect with iot hub
– Sunday
Aug 27 at 8:14





@JoeyCai I cant open that Solution on VS2013 , VS2015 and VS2017
– Sunday
Aug 27 at 8:20




1 Answer
1



I follow this tutorial to create an ASP.NET Core MVC application. Install Microsoft.Azure.Devices(version 1.17.0) from NuGet. Call the regManager.GetDevicesAsync() in the controller and get the result successfully.



ManageDevices.cs in Controllers:


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Devices;
using Microsoft.Azure.Devices.Common.Exceptions;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace WebApplication1.Controllers

public class ManageDevices : Controller

public static string IOTHUBSTRING = "HostName=[IOT HUB NAME].azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=[KEY]";


// GET: /<controller>/
public string Index()

return "This is my default action...";


public IActionResult GetDevices()

GetDevicesAsync();
return View();


public async static Task<IEnumerable> GetDevicesAsync(int deviceCount = 8)


var regManager = RegistryManager.CreateFromConnectionString(IOTHUBSTRING);

var devices = await regManager.GetDevicesAsync(deviceCount);

foreach (var device in devices)

string deviceId = device.Id;
DeviceStatus status = device.Status;


return devices;





You can use the following URI to execute the GetDevices method:


https://localhost:44387/ManageDevices/GetDevices



enter image description here



The result of the got devices:



enter image description here



You can have a try to see if it helps.



Update:



You can access the following device datas:



enter image description here





Thank you for your reply. I tried to connect but I could not to get devices from iot hub. When i tried to connect internet directly I can get devices from iot hub. So i think the reason might be corporate network's proxy. Could you please consider again and let me know if you know anything.
– Sunday
Aug 31 at 8:02





@Sunday It seems a known issue and it has been fixed already for .net SDK. Here is a sample of how to set the proxy explicitly in the application. Can you have a try and let me know if it helps.
– Rita Han - MSFT
Sep 3 at 2:04






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế