hi
Can the Get method be asynchronous?
Otherwise, try AysncHelper
[HighlightedMember]
[UnitOfWork(isTransactional: false)]
public virtual BookStore.Test.Test Get()
{
return AsyncHelper.RunSync(() => _repo.FirstAsync());
}
Yes
Please try to add MultipleActiveResultSets=true.
they seem to be the same as the examples
They are different. Please remove the scopeServer.Dispose();
public BookStore.Test.Test Get()
{
using (var scopeServer = _scopedServiceProvider.GetService())
{
var res = scopeServer.Service.Get();
//scopeServer.Dispose();
return res;
}
}
The connection does not support MultipleActiveResultSets.
Do you have MultipleActiveResultSets=True in your connection string?
Cannot access a disposed context instance. A common cause of this error is disposing a context instance that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances. Object name: 'BookStoreDbContext'.
Code from a client. They don't have this problem, please try.
using System;
using Microsoft.Extensions.DependencyInjection;
namespace Acme.Bookstore
{
public interface IScopedServiceProvider<TService>
{
ServiceScopeScope<TService> GetService();
}
public class ScopedServiceProvider<TService> : IScopedServiceProvider<TService>
{
private readonly IServiceProvider _provider;
public ScopedServiceProvider(IServiceProvider provider)
{
this._provider = provider ?? throw new ArgumentNullException(nameof(provider));
}
public ServiceScopeScope<TService> GetService()
{
var scope = _provider.CreateScope();
return new ServiceScopeScope<TService>(scope);
}
}
public class ServiceScopeScope<TService> : IDisposable
{
private readonly IServiceScope _scope;
public ServiceScopeScope(IServiceScope scope)
{
_scope = scope ?? throw new ArgumentNullException(nameof(scope));
Service = scope.ServiceProvider.GetRequiredService<TService>();
}
public TService Service { get; }
public void Dispose()
{
_scope.Dispose();
}
}
}
using Acme.Bookstore.Books;
using Acme.Bookstore.Repositories;
using Acme.Bookstore.Users;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;
namespace Acme.Bookstore.ReportingServices
{
[ExposeServices(typeof(ReportingDataSourceServiceDecorator))]
public class ReportingDataSourceServiceDecorator : IReportingDataSourceService, ITransientDependency
{
private readonly IScopedServiceProvider<ReportingDataSourceService> _scopedServiceProvider;
public ReportingDataSourceServiceDecorator(IScopedServiceProvider<ReportingDataSourceService> scopedServiceProvider)
{
_scopedServiceProvider = scopedServiceProvider;
}
public IList<BookDto> GetAllBooks()
{
using (var scopeServer = _scopedServiceProvider.GetService())
{
return scopeServer.Service.GetAllBooks();
}
}
}
public class ReportingDataSourceService : ApplicationService, IReportingDataSourceService
{
private readonly IBookCustomRepository _bookRepo;
public ReportingDataSourceService()
{
// We use this parameterless constructor in the Data Source Wizard only, and not for the actual instantiation of the repository object.
throw new NotSupportedException();
}
public ReportingDataSourceService(IBookCustomRepository bookRepo)
{
_bookRepo = bookRepo;
}
[UnitOfWork]
public virtual IList<BookDto> GetAllBooks()
{
var query = _bookRepo.GetAllBooksAsync();
return ObjectMapper.Map<IList<Book>, IList<BookDto>>(
query.Result.ToList()
);
}
}
}
https://support.abp.io/QA/Questions/978/How-can-I-debug-in-the-source-code-of-ABP-framework https://support.abp.io/QA/Questions/2082/Where-can-I-find-a-guide-to-debugging-ABP https://github.com/abpframework/abp/issues/1039
AuthServer first returns the access_token, and the Web will check it, and try to use it to get UserInfo. But AuthServer says it doesn't exist. I really don't understand.
It seems that the HTTP request has been tampered with.
[09:31:12 INF] Executing SignInResult with authentication scheme (OpenIddict.Server.AspNetCore) and the following principal: System.Security.Claims.ClaimsPrincipal.
[09:31:12 INF] The token 'eee2d6af-f98a-0c19-2a7a-3a091e7db469' was successfully marked as redeemed.
[09:31:12 INF] The response was successfully returned as a JSON document: {
"access_token": "[redacted]",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "openid profile roles email phone AccountService AdministrationService ProductService",
"id_token": "[redacted]"
}.
[09:31:12 INF] Executed action Volo.Abp.OpenIddict.Controllers.TokenController.HandleAsync (Volo.Abp.OpenIddict.AspNetCore) in 86.1095ms
[09:31:12 INF] Executed endpoint 'Volo.Abp.OpenIddict.Controllers.TokenController.HandleAsync (Volo.Abp.OpenIddict.AspNetCore)'
[09:31:12 INF] Request finished HTTP/1.1 POST http://authserver.domain.in/connect/token application/x-www-form-urlencoded 193 - 200 2732 application/json;charset=UTF-8 235.7982ms
[09:31:12 INF] Request starting HTTP/1.1 GET http://authserver.domain.in/connect/userinfo - -
[09:31:12 INF] The request URI matched a server endpoint: Userinfo.
[09:31:12 INF] The userinfo request was successfully extracted: {}.
[09:31:12 INF] The userinfo request was rejected because the mandatory 'access_token' parameter was missing.
[09:31:12 INF] The response was successfully returned as a challenge response: {
"error": "missing_token",
"error_description": "The mandatory 'access_token' parameter is missing.",
"error_uri": "https://documentation.openiddict.com/errors/ID2029"
}.
[09:31:12 INF] Request finished HTTP/1.1 GET http://authserver.domain.in/connect/userinfo - - - 302 0 - 9.2758ms
[09:31:12 INF] Request starting HTTP/1.1 GET http://authserver.domain.in/Error?httpStatusCode=401 - -
scriptUrl: "/Pages/Locations/editModal.js?" + (Math.random() + 1).toString().substring(2),
Would adding some random strings work?
A DbContext can only be created inside a unit of work!
https://docs.abp.io/en/abp/latest/Unit-Of-Work#begin-a-new-unit-of-work
hi
Maybe localhost does not support sub-domain names, you can try a domain name like https://readme.localtest.me/.
hi
Please send the AuthServer logs as well.
hi
Can you share these logs by email?
Web and AuthServer