C# LoginAsync有时会超时

C# LoginAsync有时会超时,c#,authentication,azure-mobile-services,C#,Authentication,Azure Mobile Services,我有从WPF客户端调用的Azure托管移动应用程序的一些身份验证代码。作为包含身份验证服务的Prism模块初始化的一部分,它尝试对用户进行身份验证。用于身份验证的异步方法编写如下: public async Task AcquireTokenAndAuthenticateWebApiAsync() { try { //todo these are hardcoded :-( ... need to come from app settings!!

我有从WPF客户端调用的Azure托管移动应用程序的一些身份验证代码。作为包含身份验证服务的Prism模块初始化的一部分,它尝试对用户进行身份验证。用于身份验证的异步方法编写如下:

public async Task AcquireTokenAndAuthenticateWebApiAsync()
{
    try
    {
        //todo these are hardcoded :-(  ... need to come from app settings!!

        // settings for authentication
        string resourceId = "https://windinspectordevmobileappservice.azurewebsites.net";
        //string resourceId = "http://localhost:51293/";

        string clientId = "5fe3b968-1d23-4667-9c31-86fac4ab4aec";
        Uri redirectUri = new Uri("https://windinspectordevmobileappservice.azurewebsites.net/.auth/login/done"); // Page to say you have sucessfully signed in
        const string appServiceUrl = "https://windinspectordevmobileappservice.azurewebsites.net";
        string authorityUri = "https://login.windows.net/dnv.onmicrosoft.com";


        this.authContext = new AuthenticationContext(authorityUri);

        // authenticate against the AD
        var result = await authContext.AcquireTokenAsync(
                resourceId, clientId, redirectUri,
                new PlatformParameters(PromptBehavior.Auto, false));

        this.authResult = result;


        // authenticate against the web api
        Client = new MobileServiceClient(appServiceUrl);
        JObject payload = new JObject();
        payload["access_token"] = authResult.AccessToken;

        var user = await Client.LoginAsync(
            MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory,
            payload).ConfigureAwait(false);

        this.authenticatedUserName = this.authResult.UserInfo.DisplayableId;
    }
    catch (InvalidOperationException e)
    {

    }
}
对LoginAsync的调用成功率约为50%。但是,在其他时间,LoginAsync调用只是超时(任务超时时出现异常)。这是什么原因造成的

我已尝试打开客户端中的日志,但在日志中看不到超时的原因:

来自成功LoginAsync调用的应用程序日志:

2017-01-27T16:24:29  PID[23292] Verbose     Received request: POST https://windinspectordevmobileappservice.azurewebsites.net/.auth/login/aad

2017-01-27T16:24:29  PID[23292] Verbose     JWT validation succeeded. Subject: '__HeuajpWfXmUxZBrDvwAqcV0UOirMVrs5iCwvpnrrY', Issuer: 'https://sts.windows.net/adf10e2b-b6e9-41d6-be2f-c12bb566019c/'.

2017-01-27T16:24:29  PID[23292] Information Login completed for 'max.palmer@dnvgl.com'. Provider: 'aad'.

2017-01-27T16:24:29  PID[23292] Information Sending response: 200.77 OK

2017-01-27 16:24:29 WINDINSPECTORDEVMOBILEAPPSERVICE POST /.auth/login/aad X-ARR-LOG-ID=4f08

LoginAsync调用中超时的应用程序日志:

734a-75e2-4674-a9c8-bd74caa1aa3f 443 - 80.5.95.115 ZUMO/3.1+(lang=Managed;+os=Windows;+os_version=6.2.0.9200;+arch=Win32NT;+version=3.1.50105.0) - - windinspectordevmobileappservice.azurewebsites.net 200 77 0 1089 2739 109

2017-01-27T16:26:29  No new trace in the past 1 min(s).

2017-01-27T16:26:34  PID[23292] Verbose     Received request: POST https://windinspectordevmobileappservice.azurewebsites.net/.auth/login/aad

2017-01-27T16:29:29  No new trace in the past 1 min(s).
注意:查看这些日志,当登录调用成功时,我会看到“JWT验证成功”,否则,我永远看不到这一行,它会超时。我在网上检查了许多使用这种身份验证模式的示例,代码对我来说很好。我还尝试过通过async命令执行方法来转换要调用的代码,这样我就一直是异步的(向上)

我还可以做些什么来了解在某些情况下超时的原因

我的一个问题是MobileServiceClient的源代码位于:

但是,此存储库被标记为已弃用(或者至少已弃用移动服务以支持移动应用)。我想这个类仍然可以用于移动应用程序


有没有办法让我进入密码?我需要从Git获取源代码并调试吗?

50%似乎有点高;但是你总是有超时的可能,应该防御性地编写代码来处理它。当然,我会这么做的。然而,它超时是很常见的。我只是不知道是什么原因造成的-除了对LoginAsync方法的调用之外,我无法确定告诉我什么超时的信息源。如果他们将符号发布到symbolsource,那么您可以。我们将符号发布到symbolsource。我不知道是什么原因导致了超时,因为它看起来不像auth子系统在实际响应-与移动应用程序无关(这是SDK,不涉及auth)。谢谢,我将尝试向下推到调用堆栈中。