Azure DocumentDB .NET SDK does not contains all HTTP Status Codes - c#

When you look at the document of HTTP status codes that CosmosDB REST API returns, there are some status codes that does not exist in .NET SDK.
HTTP Status Codes for Azure Cosmos DB
Suppose, status code 449, does not exist in the HttpStatusCode(System.Net).
"449 Retry With"
The operation encountered a transient error.
This only occurs on write operations.
It is safe to retry the operation.
How do you handle this sort of status code using the Azure DocDb's .NET client SDK?
Or does the SDK handles these by itself?

As you said, if we check the StatusCode property (that is nullable) of DocumentClientException, we will find that status code 449 does not exist in the System.Net.HttpStatusCode.
After check the source of Azure DocumentDB .NET SDK, the SDK seems handle these by itself.

Related

Unable to use swagger 3.0.1 in Azure logic apps

When I try to add a swagger endpoint from my logic app it fails even though it successfully fetches the content.
Failed to fetch swagger with error message: Invalid response: {"openapi":"3.0.1","info":{"title":"My Swagger API"
...
...
...} Ensure you have CORS enabled on the endpoint and are calling a valid HTTPS endpoint.
I tried trouble-shooting CORS in every possible way, but in the end what got it working was forcing version 2.0 of swagger:
app.UseSwagger(o => o.SerializeAsV2 = true);
Has anyone gotten swagger 3.x to work with Logic Apps?
Okay, I have replicated the issue on my end and I have observed the same issue with the my open API.
The key word to notice here is "OpenAPI" specification. This is not a swagger specification. I found the official document which clearly says Swagger(not OpenAPI). Please refer Call REST endpoints by using Azure Logic Apps
You can try work around for this by creating custom connector

401 Unauthorized when querying durable function status

I need some help with Azure Durable Functions.
I created a new durable function with VS Code in C# and deployed it to Azure via the VS Code azure function extension. The function app resource was already created manually in the portal. I use
FUNCTIONS_WORKER_RUNTIME: dotnet
FUNCTIONS_EXTENSION_VERSION: ~2
I can trigger the creation of an durable task and but when I query the status with the statusQueryGetUri, I only get a 401 Unauthrized. The http trigger of the function itself is anonymous and does not require authentication (for debug purpose only).
The requests look like this (I used Postman to send the requests):
HTTP POST https://{function-app}.azurewebsites.net/api/SayHello_HttpStart
Response:
{
"id": "da3259a462084e86a34f8ce9859a6ed6",
"statusQueryGetUri": "https://{function-app}.azurewebsites.net/runtime/webhooks/durabletask/instances/da3259a462084e86a34f8ce9859a6ed6?taskHub=DurableFunctionsHub&connection=Storage&code=ua4tHacVv9JDH5phKCJI1OdKGXQSB/MMUX8WIv1E0OyZANqrRY3L/g==",
"sendEventPostUri": "https://{function-app}.azurewebsites.net/runtime/webhooks/durabletask/instances/da3259a462084e86a34f8ce9859a6ed6/raiseEvent/{eventName}?taskHub=DurableFunctionsHub&connection=Storage&code=ua4tHacVv9JDH5phKCJI1OdKGXQSB/MMUX8WIv1E0OyZANqrRY3L/g==",
"terminatePostUri": "https://{function-app}.azurewebsites.net/runtime/webhooks/durabletask/instances/da3259a462084e86a34f8ce9859a6ed6/terminate?reason={text}&taskHub=DurableFunctionsHub&connection=Storage&code=ua4tHacVv9JDH5phKCJI1OdKGXQSB/MMUX8WIv1E0OyZANqrRY3L/g==",
"rewindPostUri": "https://{function-app}.azurewebsites.net/runtime/webhooks/durabletask/instances/da3259a462084e86a34f8ce9859a6ed6/rewind?reason={text}&taskHub=DurableFunctionsHub&connection=Storage&code=ua4tHacVv9JDH5phKCJI1OdKGXQSB/MMUX8WIv1E0OyZANqrRY3L/g==",
"purgeHistoryDeleteUri": "https://{function-app}.azurewebsites.net/runtime/webhooks/durabletask/instances/da3259a462084e86a34f8ce9859a6ed6?taskHub=DurableFunctionsHub&connection=Storage&code=ua4tHacVv9JDH5phKCJI1OdKGXQSB/MMUX8WIv1E0OyZANqrRY3L/g=="
}
The Get Request is then simply:
GET https://{function-app}.azurewebsites.net/runtime/webhooks/durabletask/instances/da3259a462084e86a34f8ce9859a6ed6?taskHub=DurableFunctionsHub&connection=Storage&code=ua4tHacVv9JDH5phKCJI1OdKGXQSB/MMUX8WIv1E0OyZANqrRY3L/g==
Did I miss some configuration I have to set to allow access to the uri? What logs might help me figure out what the problem is?
When I run the code locally there are no problems and everything works as expected.
Thanks a lot for all help!
Note that the statusQueryGetUri is an admin endpoint which always requires a System Key.
GET <rootUrl>/runtime/webhooks/durabletask/instances/<GUID>
?taskHub={taskHub}
&connection={connection}
&code={systemKey}
As an alternative, you could also set the x-functions-key header of the http request with this key.
More info on the usage of the HTTP endpoints in the docs.

Microsoft Graph Subscription ExtensionError - Delete / Update

Issue
I currently have an Azure Active Directory Application that has a Microsoft Graph Webhook Subscription listening for new emails (messages) in a specified mailbox.
The subscription has a scheduled task that renews the subscription's expiration date via an Update request. The subscription is targeted using its MS Graph Provided ID.
Any DELETE or UPDATE request against this specific subscription fails. (See 'Error Response' below.)
Question
I realize that this may be the same issue / bug as the question presented here: https://stackoverflow.com/a/53111286/7902641
Has there been any fix / resolution / or workaround for this?
If there has been a fix or this is a different problem altogether, what can I do to resolve this specific issue?
Thanks!
Error Response
{
"error": {
"code": "ExtensionError",
"message": "Operation: Delete; Exception: [Status Code: NotFound; Reason: The subscription with Id 'Q0IzOUZCMTYtMTk4OC00OEZDLUFFQjQtNzI4NTU1MDREMkVDXzQ5RDk2MzI3LUFDRDEtNEE2QS05QTQ1LUYwQ0ZGQjgwNEQ0Qg==' is not found.]",
"innerError": {
"request-id": "e83fe463-....-....-....-76eb35e2e697",
"date": "2019-03-22T02:35:14"
}
}
}
Extra Info
Somehow the Microsoft Graph ID for the subscription is...transformed? The original subscription ID is ( 528b79f1-....-....-....-360c0e1149e9 ) and the returned target ID is: ( Q0IzOUZ ... NEQ0Qg== ) .
The executing UPDATE request originates from an ASP.NET CORE application, using the Microsoft Graph SDK (C#).
https://github.com/microsoftgraph/msgraph-sdk-dotnet
However I have eliminated the SDK as the origination of the problem -- using a REST API tester (Insomnia), I achieve the same error result. The request URL looks like:
https://graph.microsoft.com/v1.0/subscriptions/528b79f1-....-....-....-360c0e1149e9
I have also attempted to use the BETA version instead of v1.0. Unfortunately I get the same error result.
Configuration
Application:
Registered Azure Active Directory Daemon Application
Authentication Library:
MSAL
https://github.com/AzureAD/microsoft-authentication-library-for-dotnet
Calling Application (generating the update / delete request):
ASP.NET CORE (2.1) - Web Api
Using MS Graph SDK (Github link posted above)
== Update ==
The subscription in question has now expired and disappeared from my application's subscriptions list (timestamp, PST: 3/22/2019 8:45:22 AM).
I will no longer be able to test against it (sorry S.O. posterity!).
However, good news: now that the problem child (subscription) in question is gone, I was able to create a new subscription and restart my affected service. I am able to successfully submit get / update / delete requests against any newly created subscriptions.
== Update ==
The subscription in question has now expired and disappeared from my application's subscriptions list (timestamp, PST: 3/22/2019 8:45:22
AM).
I will no longer be able to test against it (sorry S.O. posterity!).
However, good news: now that the problem child (subscription) in question is gone, I was able to create a new subscription and restart
my affected service. I am able to successfully submit get / update /
delete requests against any newly created subscriptions.
As this post is almost a year old and was most likely resolved via a fix by MSFT (no actionable fixes in our implementations), I am marking this post as "answered".
#baywet Thank you for the suggestion to do so.

Azure Notification Hubs Register Device Error 404

This is the first time I'm using Azure Notification Hubs and I'm having some trouble getting it working properly with my application.
The part I'm stuck on (at the moment) is registering my device with the notification hub. I'm using the backend method to do the registration ... that is, I'm creating an Installation object and using the CreateOrUpdateInstallationAsync method to register the device via my Web API. I'm only testing it at this stage so I'm hitting my API endpoint with dummy data via Postman.
When I step through my code, I'm getting the following error when I execute CreateOrUpdateInstallationAsync ...
The remote server returned an error: (404) Not Found. Entity does not
exist.TrackingId:203cba37-007d-4dcb-ae25-ced33fa012aa_G1,TimeStamp:2/4/2018
10:24:02 PM
I've tested that I am connecting to the Notification Hub correctly by calling GetAllRegistrationsAsync. This returns an empty list (expected) and no error ... so I have my endpoints set up correctly. I'm wondering if there is a problem with my dummy data? For the installation Id, I've just created a random GUID (Guid.NewGuid). The Device ID and Push Notification Handle are random numbers and letters. And I'm testing this for the Android platform (NotificationPlatform.Gcm).
Has anyone seen this error before and know what it means? Am I able to just use random data for testing purposes (I'm only interested in registering devices at this stage) or do I need legitimate data (real device id's, etc)?
Thanks in advance.
The CreateOrUpdateInstallationAsync method would essentially invoke the REST API Create or Overwrite an Installation. When you register with a notification hub from your custom backend using the Installation, the core code would look like as follows:
NotificationHubClient hubclient = NotificationHubClient.CreateClientFromConnectionString(listenConnString, hubName);
await hubclient.CreateOrUpdateInstallationAsync(installation);
Note: You could install the Microsoft.Azure.NotificationHubs package for back end operations.
For a simpler way, I just created a console application and test this operation as follows:
Note: I just created a new Azure Notification Hub and did not set any notification settings. And I set a GUID as the InstallationId and a random string as the PushChannel, the rest operation could work as expected.
And I could retrieve the previous added registration as follows:
Has anyone seen this error before and know what it means? Am I able to just use random data for testing purposes (I'm only interested in registering devices at this stage) or do I need legitimate data (real device id's, etc)?
The operation could work on my side, I would recommend you debug your application and leverage fiddler to capture the network traces to narrow this issue. Moreover, you could follow Registration management for more details about registering devices with azure notification hubs.
Ok, it turns out that I had the wrong value for Hub Name when instantiating the NotificationHub object using NotificationHubClient.CreateClientFromConnectionString. I was using the namespace, instead of the hub name (visible on the Overview tab in the Azure Portal).

MobileServiceTable.InsertAsync ZUMO-API-VERSION Error

I'm trying to migration Azure Mobile Service to Azure App Services. In C# I'm using MobileServiceClient.GetTable to get a MobileServiceTable object. With this I try to insert an object using MobileServiceTable.InsertAsync.
After upgrading I am getting the error-
An invalid API version was specified in the request, this request needs to specify a ZUMO-API-VERSION of 2.0.0
I understand the error, but I don't know how to update the request headers to add this. Is this possible?
You need to update the SDK. Remove the WindowsAzure.MobileServices SDK and add the Microsoft.Azure.Mobile.Client SDK. If you use offline-sync, then replace the equivalent SQLiteStore packages as well.
For more information, see https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-net-upgrading-from-mobile-services

Categories