gpt4 book ai didi

c# - IdentityModel SetBearerToken 系统

转载 作者:行者123 更新时间:2023-12-05 06:39:16 28 4
gpt4 key购买 nike

使用 .net 4.7 和 IdentityModel 的 Windows 服务应用程序。这是一个 Windows 服务:它在我的机器 (Windows 10) 上运行良好,但在 Windows Server 2008 r2 上运行不正常。

    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但它并没有解决我的问题:如果我使用那个解决方案,我会得到另一个异常。

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 ---

最佳答案

您可能缺少 using 指令:

using IdentityModel.Client;

关于c# - IdentityModel SetBearerToken 系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44794384/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com