TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
2.1k
480.6k
UnathorizedException Error?
Sep 12 2019 1:56 AM
Hi Team
I am writing a back end application in C# using Azure SDK to the portal, but the exception im getting is as follow;
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
Microsoft.Azure.Devices.Client;
using
Microsoft.Azure.Devices.Common;
using
Microsoft.Azure.Devices.Shared;
using
Microsoft.Azure.Devices;
namespace
BackEndApplication
{
class
Program
{
private
static
ServiceClient _serviceClient;
private
readonly
static
string
s_connectionString =
"HostName=UniversityIOTHub.azure-devices.net;DeviceId=UniversityDeviceIOT;SharedAccessKey=U433bDviQRc4QlxyZSO+9sZ1d6fY94CJg2AMh+bF78g="
;
private
static
async Task InvokeMethod()
{
var methodInvocation =
new
CloudToDeviceMethod(
"SetTelemetryInterval"
) { ResponseTimeout = TimeSpan.FromSeconds(30) };
methodInvocation.SetPayloadJson(
"10"
);
var response = await _serviceClient.InvokeDeviceMethodAsync(
"UniversityDeviceIOT"
, methodInvocation);
Console.WriteLine(
"Response status:{0}, payload"
, response.Status);
Console.WriteLine(response.GetPayloadAsJson());
}
static
void
Main(
string
[] args)
{
Console.WriteLine(
"IOT Hub Test-- BackEndApplication.\n"
);
_serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString);
InvokeMethod().GetAwaiter().GetResult();
Console.WriteLine(
"Press Enter to exit."
);
Console.ReadLine();
}
}
}
Microsoft.Azure.Devices.Common.Exceptions.UnauthorizedException
HResult=0x80131500
Message={"Message":"{\"errorCode\":401002,\"trackingId\":\"56456d99a904426686d7547826371c50-G:2-TimeStamp:09/12/2019 06:54:47\",\"message\":\"Unauthorized\",\"timestampUtc\":\"2019-09-12T06:54:47.6295403Z\"}","ExceptionMessage":""}
Source=Microsoft.Azure.Devices
StackTrace:
at Microsoft.Azure.Devices.HttpClientHelper.<ExecuteAsync>d__36.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Devices.HttpClientHelper.<PostAsync>d__27`2.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at BackEndApplication.Program.<InvokeMethod>d__2.MoveNext() in C:\Users\Gcobanim\source\repos\BackEndApplication\Program.cs:line 25
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at BackEndApplication.Program.Main(String[] args) in C:\Users\Gcobanim\source\repos\BackEndApplication\Program.cs:line 36
Reply
Answers (
4
)
System.Net.Sockets.SocketException
DeviceNotFoundException