首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >IdentityModel SetBearerToken系统

IdentityModel SetBearerToken系统
EN

Stack Overflow用户
提问于 2017-06-28 05:37:46
回答 1查看 4.8K关注 0票数 3

使用.net 4.7和IdentityModel的Windows应用程序。它是一个windows服务:它在我的机器(windows 10)上工作得很好,但在windows 2008 r2上却不是。

代码语言:javascript
运行
复制
    public async Task<bool> ConnectAsync()
    {
        bool retValue = true;

        try
        {
            var client = new DiscoveryClient(FileWatcherDefinitions.PortalBaseAddress);
            var doc = await client.GetAsync();

            retValue = !doc.IsError;

            if (retValue)
            {
                var result = doc.TokenEndpoint;
                var tokenClient = new TokenClient(doc.TokenEndpoint, 
                    FileWatcherDefinitions.PortalClientName, 
                    FileWatcherDefinitions.PortalClientPassword);
                var tokenResponse = await tokenClient.RequestClientCredentialsAsync(FileWatcherDefinitions.PortalWebApiResource);

                retValue = !tokenResponse.IsError;

                if (retValue)
                {
                    _httpClient = new HttpClient();
                    _httpClient.SetBearerToken(tokenResponse.AccessToken);
                    // _httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", tokenResponse.AccessToken);
                }
            }
        }
        catch(Exception exc)
        {
            retValue = false;
        }

        return retValue;
    }


exception: System.AggregateException: One or more errors occurred. ---> System.MissingMethodException: Method not found: 'Void System.Net.Http.HttpClientExtensions.SetBearerToken(System.Net.Http.HttpClient, System.String)'.
   at RICustomerServiceFileWatcher.RICustomerServicePortalWebApiClient.<ConnectAsync>d__1.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at RICustomerServiceFileWatcher.RICustomerServicePortalWebApiClient.ConnectAsync()
   at RICustomerServiceFileWatcher.FileWatcherTimeManager.<>c__DisplayClass8_0.<<InitialOrderCheck>b__10>d.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at RICustomerServiceFileWatcher.FileWatcherTimeManager.InitialOrderCheck()
---> (Inner Exception #0) System.MissingMethodException: Method not found: 'Void System.Net.Http.HttpClientExtensions.SetBearerToken(System.Net.Http.HttpClient, System.String)'.
   at RICustomerServiceFileWatcher.RICustomerServicePortalWebApiClient.<ConnectAsync>d__1.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at RICustomerServiceFileWatcher.RICustomerServicePortalWebApiClient.ConnectAsync()
   at RICustomerServiceFileWatcher.FileWatcherTimeManager.<>c__DisplayClass8_0.<<InitialOrderCheck>b__10>d.MoveNext()<---

我已经看过Precompiled Azure Function throwing error on HttpClientExtensions.SetBearerToken use, CSX doesn't了,但它并没有解决我的问题:如果我使用该解决方案,就会得到另一个异常。

代码语言:javascript
运行
复制
System.AggregateException: One or more errors occurred. ---> System.MissingMethodException: Method not found: 'Void IdentityModel.Client.DiscoveryClient..ctor(System.String, System.Net.Http.HttpMessageHandler)'.
   at RICustomerServiceFileWatcher.RICustomerServicePortalWebApiClient.<ConnectAsync>d__1.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at RICustomerServiceFileWatcher.RICustomerServicePortalWebApiClient.ConnectAsync()
   at RICustomerServiceFileWatcher.FileWatcherTimeManager.<>c__DisplayClass8_0.<<InitialOrderCheck>b__10>d.MoveNext()
   --- End of inner exception stack trace ---
EN

回答 1

Stack Overflow用户

发布于 2022-01-31 08:55:14

您可能缺少了一个使用指令:

代码语言:javascript
运行
复制
using IdentityModel.Client;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44794384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档