[英]HTTP Endpoint not working with Elsa ERR_CONNECTION_REFUSED
I tried creating a web app in .Net standard 6.0 and added a simple workflow for HTTP Endpoint requests & responses.我尝试在 .Net 标准 6.0 中创建一个 Web 应用程序,并为 HTTP 端点请求和响应添加了一个简单的工作流程。 but the server URL returning ERR_CONNECTION_REFUSED with the URL(https://localhost:5001/data).但服务器 URL 返回 ERR_CONNECTION_REFUSED 和 URL(https://localhost:5001/data)。 I have added my source code details, Please let me know if anything else required for understanding the issue.我已经添加了我的源代码详细信息,请让我知道是否需要其他任何东西来理解这个问题。
Program.cs程序.cs
using Elsa;
using Elsa.Persistence.EntityFramework.Core.Extensions;
using Elsa.Persistence.EntityFramework.Sqlite;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var builder = WebApplication.CreateBuilder(args);
var elsaSection = builder.Configuration.GetSection("Elsa");
// Elsa services.
builder.Services
.AddElsa(elsa => elsa
.UseEntityFrameworkPersistence(ef => ef.UseSqlite())
.AddConsoleActivities()
.AddHttpActivities(elsaSection.GetSection("Server").Bind)
.AddQuartzTemporalActivities()
.AddWorkflowsFrom<Startup>()
);
// Elsa API endpoints.
builder.Services.AddElsaApiEndpoints();
builder.Services.AddCors(cors => cors.AddDefaultPolicy(policy => policy
.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin()
.WithExposedHeaders("Content-Disposition"))
);
// For Dashboard.
builder.Services.AddRazorPages();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app
.UseStaticFiles()
.UseCors()
.UseHttpActivities()
.UseRouting()
.UseEndpoints(endpoints =>
{
// Elsa API Endpoints are implemented as regular ASP.NET Core API controllers.
endpoints.MapControllers();
// For Dashboard.
endpoints.MapFallbackToPage("/_Host");
});
app.Run();
Appsetting.json应用设置.json
"Elsa": {
"Server": {
"BaseUrl": "https://localhost:5001"
}
}
}
--------------------------------------------------------------
Exported workflow details
{
"$id": "1",
"definitionId": "77bbdbc2d83e402082292c26a054cdce",
"versionId": "2f40a957f6474d9f9a6291116407bda3",
"name": "data",
"displayName": "data",
"version": 1,
"variables": {
"$id": "2",
"data": {}
},
"customAttributes": {
"$id": "3",
"data": {}
},
"isSingleton": false,
"persistenceBehavior": "WorkflowBurst",
"deleteCompletedInstances": false,
"isPublished": true,
"isLatest": true,
"activities": [
{
"$id": "4",
"activityId": "e7685474-cbb7-44af-b15c-72d68897f537",
"type": "HttpEndpoint",
"displayName": "HTTP Endpoint",
"persistWorkflow": false,
"loadWorkflowContext": false,
"saveWorkflowContext": false,
"properties": [
{
"$id": "5",
"name": "Path",
"expressions": {
"$id": "6",
"Literal": "/data"
}
},
{
"$id": "7",
"name": "Methods",
"expressions": {
"$id": "8",
"Json": "[\"GET\"]"
}
},
{
"$id": "9",
"name": "ReadContent",
"expressions": {
"$id": "10"
}
},
{
"$id": "11",
"name": "TargetType",
"expressions": {
"$id": "12"
}
},
{
"$id": "13",
"name": "Schema",
"syntax": "Literal",
"expressions": {
"$id": "14",
"Literal": ""
}
},
{
"$id": "15",
"name": "Authorize",
"expressions": {
"$id": "16"
}
},
{
"$id": "17",
"name": "Policy",
"expressions": {
"$id": "18"
}
}
],
"propertyStorageProviders": {}
},
{
"$id": "19",
"activityId": "e447ad59-8482-43ed-958d-2f044b6ac672",
"type": "WriteHttpResponse",
"displayName": "HTTP Response",
"persistWorkflow": false,
"loadWorkflowContext": false,
"saveWorkflowContext": false,
"properties": [
{
"$id": "20",
"name": "Content",
"expressions": {
"$id": "21"
}
},
{
"$id": "22",
"name": "ContentType",
"expressions": {
"$id": "23"
}
},
{
"$id": "24",
"name": "StatusCode",
"expressions": {
"$id": "25",
"Literal": "OK"
}
},
{
"$id": "26",
"name": "CharSet",
"expressions": {
"$id": "27",
"Literal": "utf-8"
}
},
{
"$id": "28",
"name": "ResponseHeaders",
"expressions": {
"$id": "29",
"Literal": "data"
}
}
],
"propertyStorageProviders": {}
}
],
"connections": [
{
"$id": "30",
"sourceActivityId": "e7685474-cbb7-44af-b15c-72d68897f537",
"targetActivityId": "e447ad59-8482-43ed-958d-2f044b6ac672",
"outcome": "Done"
}
],
"id": "2f40a957f6474d9f9a6291116407bda3"
}````
Thanks in advance.
When you want to invoke an HTTP endpoint, you need to use the same port as the one that is hosting Elsa.当您想要调用 HTTP 端点时,您需要使用与托管 Elsa 的端口相同的端口。
For example, if you have an HTTP Endpoint activity configured with /start
as its path, and your web app is hosted at https://localhost:7095/
, then you need to make a request https://localhost:7095/start
例如,如果您的 HTTP 端点活动配置为/start
作为其路径,并且您的 Web 应用程序托管在https://localhost:7095/
,那么您需要发出请求https://localhost:7095/start
Note笔记
it is possible to configure the HTTP Endpoint middleware to listen on a subpath (which is recommended as to have the middleware not try and match each and every requests against a workflow).可以将 HTTP 端点中间件配置为侦听子路径(建议不要让中间件尝试将每个请求与工作流匹配)。 If this is the case, make sure to include this path as well.如果是这种情况,请确保也包含此路径。
For example, if you did something like this:例如,如果你做了这样的事情:
elsa.AddHttpActivities(options => options.BasePath = "/workflows");
Then the path to your HTTP Endpoint is: https://localhost:7095/workflows/start
那么你的 HTTP 端点的路径是: https://localhost:7095/workflows/start
The problem that ERR_CONNECTION_REFUSED
gives us in port 5001 is that, when we follow most of the tutorials, we leave port 5000 and/or 5001 by default of ELSA and when we create the ASP.NET Core project (at least with command lines) positions 5000 and 5001 are occupied by default, and that is why it conflicts. ERR_CONNECTION_REFUSED
在端口 5001 中给我们带来的问题是,当我们按照大多数教程进行操作时,我们会默认保留 ELSA 的端口 5000 和/或 5001,并且当我们创建 ASP.NET Core 项目时(至少使用命令行)位置5000和5001默认被占用,这就是冲突的原因。
To solve this problem, we must go to the Properties folder, in the launchSettings.json
file of our ASP.NET Web project, and in the properties change the ports, and with this you can solve the conflict.要解决这个问题,我们必须到我们的ASP.NET Web项目的launchSettings.json
文件中的Properties文件夹中,在属性中更改端口,这样就可以解决冲突了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.