我无法让我的项目(dotnet 6.0)与Solr 8.9连接,我希望有人可以帮助我

问题描述 投票:0回答:1

程序.cs

...

builder.Services.AddSolrNet<MySolrModel>("http://localhost:8983/solr/fast").BuildServiceProvider();

builder.Services.AddHttpContextAccessor();

// Add transients
builder.Services.AddTransient<UserService>();
builder.Services.AddTransient<SolrService>();
builder.Services.AddTransient<MessageService>();
builder.Services.AddTransient<FeedbackService>();
builder.Services.AddTransient<DashboardService>();
builder.Services.AddTransient<ManagementService>();
builder.Services.AddTransient<Others>();
...

其他.cs

public class Others
    {
        private readonly ISolrOperations<MySolrModel> _solr;

        public Others(ISolrOperations<MySolrModel> solr)
        {
            _solr = solr;
        }

        /// <summary>
        /// Checks if there is a connection with the Apache Solr Server
        /// </summary>
        /// <returns>True if there is a connection, False if there isn't.</returns>
        public bool CheckSolrConnection()
        {
            try
            {
                // Just sending a ping request to verify connection
                _solr.Ping();

                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error while connecting to Solr: {ex.Message}");
                return false;
            }
        }
    }

SolrService.cs(由我创建)

...
/// <summary>
        /// Makes a query to the Solr server
        /// </summary>
        /// <param name="searchString">Query for the Solr server</param>
        /// <returns>The query results</returns>
        public async Task<List<MySolrModel>> Search(string searchString)
        {
            if (searchString.Equals("*:*"))
            {
                var results = await _solr.QueryAsync(SolrQuery.All);
                return results;
            }
            else
            {
                var results = await _solr.QueryAsync(searchString);
                return results;
            }
        }
...

我在服务器端收到此错误:

Exception thrown: 'SolrNet.Exceptions.SolrConnectionException' in SolrNet.dll
Error while connecting to Solr: Cannot assign requested address [::1]:8983 (localhost:8983)

*AND*

System.InvalidOperationException: The exception handler configured on ExceptionHandlerOptions produced a 404 status response. This InvalidOperationException containing the original exception was thrown since this is often due to a misconfigured ExceptionHandlingPath. If the exception handler is expected to return 404 status responses then set AllowStatusCode404Response to true.
 ---> System.Net.Http.HttpRequestException: Cannot assign requested address (localhost:8983)
 ---> System.Net.Sockets.SocketException (99): Cannot assign requested address
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage request)
   at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at SolrNet.Impl.AutoSolrConnection.GetAsStreamAsync(String relativeUrl, IEnumerable`1 parameters, CancellationToken cancellationToken)
   at SolrNet.Impl.SolrQueryExecuter`1.ExecuteAsync(ISolrQuery q, QueryOptions options, CancellationToken cancellationToken)
   at ChatbotManagement.Controllers.Services.API.SolrService.Search(String searchString) in D:\Faculdade\3-Ano\Trabalhos\PF\chatbot\ChatbotManagement\Controllers\Services\API\SolrService.cs:line 207
   at ChatbotManagement.Controllers.DashboardController.UpdateDB() in D:\Faculdade\3-Ano\Trabalhos\PF\chatbot\ChatbotManagement\Controllers\DashboardController.cs:line 63
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

注释

  1. 我用postman尝试ping并查询,执行成功。
  2. 我已经对 Antivyrus 进行了破例
  3. 尝试了多种方式和配置都没有效果
  4. 如果有必要或者我记得的话,我会提供任何未来的信息
  5. 在任何人问之前,是的,当我尝试时,Solr 服务器已打开并且我已经验证了链接,是的,它是正确的
  6. 另外,我正在使用 docker,但不是 Solr,Solr 运行在我的机器上,而不是 docker,在有人问之前

我试过了

builder.Services.AddLogging(configure => configure.AddConsole()).AddSolrNet<MySolrModel>("https://localhost:8983/solr/#/ChatbotFiles").BuildServiceProvider();

而不是

builder.Services.AddSolrNet<MySolrModel>("https://localhost:8983/solr/#/ChatbotFiles");
asp.net asp.net-mvc asp.net-web-api solr solrnet
1个回答
0
投票

问题已经解决了。由于我正在访问机器的本地主机并且程序在 docker 容器内运行,因此我需要使用我的 ip 而不是本地主机。

© www.soinside.com 2019 - 2024. All rights reserved.