Detect cause of timeout in Azure Web App - c#

I am writing an bot in C# with the Microsoft Bot Framework which is hosted as Azure web app and calls either some Azure API or a Google Cloud API.
Locally everything works fine but when deployed to Azure the Call to the Google Cloud API never returns and my the Microsoft Bot Frameworks gives me an timeout error message.
I searched through the Azure portal in order to find some more detailed information why this outgoing call might not return correctly but so far I found nothing useful. I can't see any error on the diagnostics sites and remote debugging just never return from the API calls.
Does anybody know if I can enable some more debug/error information for this problem?
Edit after comments:
#Mark C.: I am able to call and get a result form the Google Service (text sentiment) when I run the app locally, so the Google Cloud API should be fine.
#Hackerman: The mapping is know to me. I try to compare some Services between Azure and Google, in this case the text sentiment API. I enabled stream logging, but there are no errors/warnings printed out.
#Bruce MSFT: The method is like this. Both azure and google paths work locally. Only the Azure path works when deployed to Azure web apps. When I remote debug the Azure Web App I can step to "client.AnalyzeSentimentAsync" and when I press next the next line is never reached. Instead after 10 (?) minutes I get an exception from mscorlib: "{"Status(StatusCode=DeadlineExceeded, Detail=\"Deadline Exceeded\")"}"
public async Task<int> DetectSentiment(string text, bool useAzure = false)
{
if (useAzure)
{
var request = new SentimentRequest();
request.Documents.Add(new AzureDocument
{
Id = Guid.NewGuid().ToString(),
Text = text
});
var client = new SentimentClient(_key);
var response = await client.GetSentimentAsync(request);
return Convert.ToInt32(response.Documents[0].Score * 100);
}
else
{
try
{
var client = LanguageServiceClient.Create();
var response = await client.AnalyzeSentimentAsync(new GoogleDocument
{
Content = text,
Type = GoogleDocument.Types.Type.PlainText
});
return Convert.ToInt32((response.DocumentSentiment.Score + 1) * 50);
}
catch (Exception ex)
{
Console.WriteLine(ex);
throw;
}
}
}

Related

Google Ads Api Console Application

I want to develop a console application that pulls all campaigns under adwords accounts using Google Ads Api.
But I could not pass the authentication step.
I do not fully understand whether I should use the Service Account or Desktop Application Flow for this process.
GoogleAdsConfig config = new GoogleAdsConfig()
{
DeveloperToken = "Dev_token",
OAuth2Mode = Google.Ads.GoogleAds.Config.OAuth2Flow.APPLICATION,
OAuth2ClientId = "client_Id",
OAuth2ClientSecret = "secrret",
OAuth2RefreshToken = " refresh_token",
};
GoogleAdsClient client = new GoogleAdsClient(config);
GoogleAdsServiceClient googleAdsService = client.GetService(Google.Ads.GoogleAds.Services.V10.GoogleAdsService);
googleAdsService.SearchStream(AdwordsClientId, query,
delegate (SearchGoogleAdsStreamResponse resp)
{
foreach (GoogleAdsRow adsRow in resp.Results)
{
}
}
);
When I try as above, I get the following error
Google.Apis.Auth.OAuth2.Responses.TokenResponseException: Error:"unauthorized_client", Description:"Unauthorized", Uri:""
What paths should i follow?
Thank you.
unauthorized_client could have a couple of reasons. The most important ones that come to mind:
Did you make sure that your client ID and client secret match?
Have you activated the Google Ads API for the GCP project whose OAuth2 client you are using?

Operation returned an invalid status code 'Forbidden`. Botframework v4

So i created a bot in azure and downloaded it. The free 1000 calls from LUIS reached its limit. I created a subscription in azure portal (I did do the docker container something). Followed this guide until step 6. When i click the endpoint url and query directly in the browser it is working fine.
I added it to the bot via Bot Emulator by clicking + sign in services and adding the bot model there. But when i run bot i get the title error. I noticed in the .bot file the authoring key and subscription key added by the bot emulator is the same.
So i changed the subscription key to the one of the keys generated by azure and still the same error. I have tried reseting the authoring key still same and deleting my luis.ai account and created a new one. (still same email because that is the one logged in azure portal.) and still the same.
Here are some pictures for reference and the error.
I also tried testing it in luis.ai and got this result.
but when i check it is set to the new resource.
Here is a pic of the bot file after adding luis via Bot emulator. It has same authoring key and subscription key (still forbidden)
so i changed it now with subscription key (still forbidden).
Here it is working properly when tested directly in the URL.
For reference:
azure portal
luis.ai
and the error
How i add luis in the bot.
Here is the code for the bot service.
using System;
using System.Collections.Generic;
using Microsoft.Bot.Builder.AI.Luis;
using Microsoft.Bot.Configuration;
namespace Microsoft.BotBuilderSamples
{
public class BotServices
{
public BotServices(BotConfiguration botConfiguration)
{
foreach (var service in botConfiguration.Services)
{
switch (service.Type)
{
case ServiceTypes.Luis:
{
var luis = (LuisService)service;
if (luis == null)
{
throw new InvalidOperationException("The LUIS service is not configured correctly in your '.bot' file.");
}
var endpoint = (luis.Region?.StartsWith("https://") ?? false) ? luis.Region : luis.GetEndpoint();
var app = new LuisApplication(luis.AppId, luis.AuthoringKey, endpoint);
var recognizer = new LuisRecognizer(app);
this.LuisServices.Add(luis.Name, recognizer);
break;
}
}
}
}
public Dictionary<string, LuisRecognizer> LuisServices { get; } = new Dictionary<string, LuisRecognizer>();
}
}
I am trying to solve this for 4 days already. Thanks!
Thank you for all of the images. That is a HUGE help! Here's the problem:
By default, your code looks for the AuthoringKey in this section (second line):
var endpoint = (luis.Region?.StartsWith("https://") ?? false) ? luis.Region : luis.GetEndpoint();
var app = new LuisApplication(luis.AppId, luis.AuthoringKey, endpoint);
var recognizer = new LuisRecognizer(app);
this.LuisServices.Add(luis.Name, recognizer);
Since your .bot file still has the authoringKey set to the one that starts with ad9c..., which has hit its limit, your bot keeps running into the 403 error.
So, in your .bot file, replace that authoringKey with one of your endpointKeys (they start with 12ccc... or b575...).
I understand your confusion with this, especially since this requires you putting an endpointKey in your authoringKey property. I know there's some changes on the horizon to how LUIS bots will use keys, but those are probably a month or more out.
Alternatively, you can change:
var app = new LuisApplication(luis.AppId, luis.AuthoringKey, endpoint);
to:
var app = new LuisApplication(luis.AppId, luis.SubscriptionKey, endpoint);
Note: If you make either of these changes, LUIS can only query (which is usually fine), since Authoring Keys do everything else (see reference, below)
References
These are not so much for you as much as others that might come across this.
Authoring vs. Endpoint Keys
Key Limits
Troubleshooting LUIS 403 Errors

Cannot Consume ASP.NET REST API Deployed Locally

I have made a very simple Web API in ASP.NET and deployed it locally with IIS, but I cannot seem to use it. I've tried using it with HTTPClient in Xamarin, as well as in Java, but something in the ASP.NET project is not allowing me to access it. I am not sure if the problem is because it's deployed locally, though. Here are the errors I receive in Java and .NET:
Java:
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
.NET:
at System.Net.Http.HttpClientHandler+<SendAsync>d__64.MoveNext () [0x00478] in <996a681f30a44cd685a4da54e11956e2>:0
Calling Method:
public async Task<List<School>> GetSchools()
{
try
{
var response = await client.GetAsync("schools");
string responseJson = await response.Content.ReadAsStringAsync();
List<School> schools = JsonConvert.DeserializeObject<List<School>>(responseJson);
return schools;
}
catch (HttpRequestException e)
{
return null;
}
}
The issue was caused by the program using an SSL Certificate. To fix, I just went into the projects properties and unchecked the setting 'Enable SSL'.

Azure mobile app return 401 (Unauthorized) even after successful login.

I'm using custom authentication with facebook to let my users login to the app service. Unfortunately I'm getting the following error when calling "InvokeApiAsync"
"Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The request could not be completed. (Unauthorized)"
I'm using the following code that worked with the 1.x.x branch of the NuGet package, Its only after updating that I get this error message.
Newtonsoft.Json.Linq.JObject jToken = new Newtonsoft.Json.Linq.JObject();
jToken.Add("access_token", token);
var user = await _mobileService.LoginAsync(MobileServiceAuthenticationProvider.Facebook, jToken);
var result= await _mobileService.InvokeApiAsync<GetContactListRequest, GetContactListResponse>("GetContactList", new GetContactListRequest());
The LoginAsync part works and the user variable contains an user with a token (_mobileService.CurrentUser does as well). It's when I call "InvokeApiAsync that i get the Unauthorized error.
The mobile service
[Authorize]
public class GetContactListController : ApiController
{
// POST api/CustomRegistration
public HttpResponseMessage Post(GetContactListRequest request)
{
try
{
return this.Request.CreateResponse(HttpStatusCode.OK, new GetContactListResponse());
}
catch (Exception ex)
{
return this.Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
}
Any pointers?
Try enabling application logging for your mobile app backend (you can do this in the portal). If the issue is in the platform authentication pipeline, then you will get more details about the auth failure there. Otherwise, it's more likely to be in your application code (either client or server).
If you have a Fiddler trace, that would also be helpful in diagnosing the problem.

Signing-in to use Live SDK, Windows Store app

I am developing an application (Windows Store) to access SkyDrive content. To login to Live I am using the below code snippet.
try
{
var uri = "https://login.live.com/oauth20_authorize.srf";
var authorizeUri = new StringBuilder(uri);
authorizeUri.AppendFormat("?client_id={0}&", "000000004C0DE9B7"); //This is my Client ID
authorizeUri.AppendFormat("scope={0}&", "wl.signin");
authorizeUri.AppendFormat("response_type={0}&", "code");
authorizeUri.AppendFormat("redirect_uri={0}", ("")); //I don't have redirect URL.
LiveAuthClient auth = new LiveAuthClient(authorizeUri.ToString());
LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.basic" });
if (loginResult != null)
{
if (loginResult.Status == LiveConnectSessionStatus.Connected)
{
this.txtStatus.Text = "Signed in";
}
}
}
catch (LiveAuthException exception)
{
this.txtStatus.Text = exception.Message+ " Error";
}
}
With this I am always getting the below exception:
"The app is not configured correctly to use Live Connect services. ..."
I tried to get Package identity for my Windows Store app. Since, it is taking me to paid registration page, I have not done that. [ https://appdev.microsoft.com/StorePortals/en-us/account/signup/start ]
I am not sure if that is the cause for the problem.
I have also tried this link to register my app. This too is not working.
https://manage.dev.live.com/build?wa=wsignin1.0
I appreciate if someone could help me in resolving this issue.
For a Windows Store app to use Live Connect APIs, it needs to have a Package Identity which you can only get my registering as a Windows Store Developer.
Windows Phone, iOS and Android apps need only the Client ID. All other apps need Client ID, Client Secret and Redirect Domain.
That is why it's not working. For more information, see: http://msdn.microsoft.com/en-us/library/live/hh826541.aspx
Hope that helps.

Categories

Resources