Search code examples
c#.netasp.net-web-api2dapr

Dapr PUB / SUB Setup for an ASP.NET Web API 2 (.NET Framework)


I need to create an ASP.NET Web API v2 micro service (.NET Framework, not .NET Core) that will work alongside a Dapr sidecar, mainly to support Pub / Sub functionality. Given this is a .NET Framework micro service, I can't use the SDK (or the related examples). I therefore need to use the HTTP API.

How do I communicate to the Dapr sidecar the PUB / SUB functionality of my micro service?

I have tried to implement:

GET http://localhost:<appPort>/dapr/subscribe

However, this never gets called?

I'm really struggling to understand how to work with Dapr using the HTTP API reference as all the example pull me back to the platform specific SDKs which I can't use.


Solution

  • I have figured this out now. In a .NET Framework app dapr will by default look at: http://127.0.0.1:/dapr/subscribe. This gets rejected by the .NET Framework IIS Express server (if that is your setup).

    To resolve the issue add the parameter '--app-channel-address localhost' in the 'dapr run' command. The subscribe endpoint will then get picked up.

    The clue in the the error logs. I would recommend if you have issues setting the parameter '--log-level error' in 'dapr run' as well. This will then remove everything but errors and make things easier to find. The default setting returns a lot more logging information