I’m just learning ELSA. I’m analysing its documents. I found a example it is name is “Hello World HTTP”
I implemented that sample. But I couldn’t take any result.
I can compile this project. I will show details below.
ELSA Documents (The example in question can be found here) : https://v2.elsaworkflows.io/docs/quickstarts/hello-world-http
Project Detail
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elsa.Activities.Http" Version="2.14.1" />
<PackageReference Include="Elsa.Core" Version="2.14.1" />
</ItemGroup>
</Project>
Program.cs
using ElsaQuickstarts.WebApp.HelloWorld;
internal class Program
{
private static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthorization();
builder.Services
.AddElsaCore(options => options
.AddHttpActivities()
.AddWorkflow<HelloWorld>());
var app = builder.Build();
app.UseRouting(); // Routing middleware
app.UseHttpActivities();
app.Run();
}
}
HelloWorld.cs
using System.Net;
using Elsa;
using Elsa.Activities.Http;
using Elsa.Builders;
namespace ElsaQuickstarts.WebApp.HelloWorld
{
/// <summary>
/// A workflow that is triggered when HTTP requests are made to /hello-world and writes a response.
/// </summary>
public class HelloWorld : IWorkflow
{
public void Build(IWorkflowBuilder builder)
{
builder
.HttpEndpoint("/hello-world") // Doğru endpoint tanımı
.WriteHttpResponse(HttpStatusCode.OK, "<h1>Hello World!</h1>", "text/html");
}
}
}
I executed this command.
PS C:Usersbarancan.gencsourcereposElsaQuickstarts.WebApp.HelloWorld> dotnet run --launch-profile https
I can see this output when I executed command.
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:8005
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:Usersbarancan.gencsourcereposElsaQuickstarts.WebApp.HelloWorld
But when i requested this address https://localhost:8005/hello-world I get the following error.
404 Not Found Error Message
I did all what exactly the document saying. I built the project and I was able to run the project.
I expect the response to change when I go to the specified address. I’m trying to understand how works ELSA
How to implement an sample with Using ELSA with .net 8.0
To integrate the Elsa’s Workflow with .NET 8, You can read through and get started with this doc.
.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elsa" Version="3.2.0" />
<PackageReference Include="Elsa.Http" Version="3.2.0" />
</ItemGroup>
</Project>
workflow class with HTTP capabilities
public class HttpHelloWorld : WorkflowBase
{
protected override void Build(IWorkflowBuilder builder)
{
builder.Root = new Sequence
{
Activities =
{
new HttpEndpoint
{
Path = new("/hello-world"),
CanStartWorkflow = true
},
new WriteHttpResponse
{
Content = new("Hello world of HTTP workflows!")
}
}
};
}
}
program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddElsa(elsa =>
{
elsa.AddWorkflow<HttpHelloWorld>();
elsa.UseHttp();
});
var app = builder.Build();
app.UseWorkflows();
app.Run();
Test Result