# Triggering a workflow on another service from a workflow/ activity

**URL:** <https://community.temporal.io/t/triggering-a-workflow-on-another-service-from-a-workflow-activity/13109>\
**Category:** Community Support\
**Tags:** dotnet-sdk\
**Created:** [August 8, 2024, 12:35pm UTC](https://community.temporal.io/t/triggering-a-workflow-on-another-service-from-a-workflow-activity/13109 "2024-08-08T12:35:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![OhMyDeera](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/ohmydeera/32/5722_2.png) [@OhMyDeera](https://community.temporal.io/u/OhMyDeera)\
**Post date:** [August 8, 2024, 12:35pm UTC](https://community.temporal.io/t/triggering-a-workflow-on-another-service-from-a-workflow-activity/13109/1 "2024-08-08T12:35:56Z")

</div>

I’ve been working on a PoC to see if Temporal can be used in our infrastructure using .NET 8.

I’ve been able to create a worker, workflow and activities, but seem to be getting stumped on triggering another workflow from the one I had just created. The other workflow exists on another service, which also has it’s own worker and activities.

How am I able to trigger that workflow to run using the output of the workflow on my service?

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [August 8, 2024, 1:13pm UTC](https://community.temporal.io/t/triggering-a-workflow-on-another-service-from-a-workflow-activity/13109/2 "2024-08-08T13:13:09Z")

</div>

You can use a Temporal client like any other client inside an activity. [Here](https://github.com/temporalio/samples-dotnet/blob/main/src/ActivitySimple/MyActivities.cs) is a sample that demonstrates a DB client used from an activity, but that can just as easily be a Temporal client.

You can also use child workflows if you need the parent/child relationship.

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [August 8, 2024, 1:14pm UTC](https://community.temporal.io/t/triggering-a-workflow-on-another-service-from-a-workflow-activity/13109/3 "2024-08-08T13:14:44Z")

</div>

(I was typing when @Chad_Retz answered the question, I will post this in case it helps anyway 🙂 )

Hi @OhMyDeera

> The other workflow exists on another service, which also has it’s own worker and activities.

I assume this means that you have two different workers listening to two different task queues (and running in different services), and each one has its activities and workflows.

> How am I able to trigger that workflow to run using the output of the workflow on my service?

- I think I would use a workflow to coordinate both as [child workflows](https://docs.temporal.io/encyclopedia/child-workflows). The parent-workflow starts the child workflow that runs in the first service. You will have to specify the same taskqueue name as the worker running in the first service when you start the child workflow.

```auto
await Workflow.ExecuteChildWorkflowAsync(
            (ChildWorkflow1 wf) => wf.RunAsync(),
            new()
            {
                Id = "my-workflow-id",
                TaskQueue = "tq-1"
            });

```

and then, pass the result to the next workflow running in service 2.

```auto

await Workflow.ExecuteChildWorkflowAsync(
            (ChildWorkflow2 wf) => wf.RunAsync(input),
            new()
            {
                Id = "my-workflow-id-2",
                TaskQueue = "tq-2"
            })

```

- Another option is to continue-as-new to a different workflowType and taskqueue. (you can set the taskqueue name in the `ContinueAsNewOptions`.

- and another one is to have an activity at the end of the first workflow that schedules the second workflow (before the first completes). You will need to inject the workflowClient into the activity, see this example : [samples-dotnet/src/DependencyInjection at main · temporalio/samples-dotnet · GitHub](https://github.com/temporalio/samples-dotnet/tree/main/src/DependencyInjection)

Antonio

---

<div class="post-metadata">

**Author:** ![OhMyDeera](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/ohmydeera/32/5722_2.png) [@OhMyDeera](https://community.temporal.io/u/OhMyDeera)\
**Post date:** [August 8, 2024, 1:26pm UTC](https://community.temporal.io/t/triggering-a-workflow-on-another-service-from-a-workflow-activity/13109/4 "2024-08-08T13:26:29Z")

</div>

Thanks both for ansering so fast!

> [@antonio.perez](#):
>
> I assume this means that you have two different workers listening to two different task queues (and running in different services), and each one has its activities and workflows.

I tried triggering a child workflow from my first workflow, but got an error saying it wasn’t registered with my worker. That makes sense since the workflow is on a seperate service with it’s own worker, so how would I register it in my service on my worker?

Currently I do something like this:

```auto
services.AddHostedTemporalWorker(
        clientTargetHost: "localhost:7233",
        clientNamespace: "default",
        taskQueue: "test-queue")
    .AddScopedActivities<MyActivities>()
    .AddWorkflow<MyWorkflow>();

```

And then from my workflow I do the following:

```auto
await Workflow.ExecuteChildWorkflowAsync("MySecondWorkflow", ["Test Param"]);

```

What needs to change for me to be able to call `MySecondWorkflow` which exists on another service?

Thank you in advance!!

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [August 8, 2024, 1:52pm UTC](https://community.temporal.io/t/triggering-a-workflow-on-another-service-from-a-workflow-activity/13109/5 "2024-08-08T13:52:40Z")

</div>

If you don’t specify the taskqueue the child workflow will be scheduled in the same taskqueue as the parent workflow, you can set a different taskqueue name in the childworkflow options.

> What needs to change for me to be able to call `MySecondWorkflow` which exists on another service?

```auto
await Workflow.ExecuteChildWorkflowAsync(
            (ChildWorkflow2 wf) => wf.RunAsync(input),
            new()
            {
                Id = "my-workflow-id-2",
                TaskQueue = "tq-2"
            })

```

> how would I register it in my service on my worker?

> <https://github.com/temporalio/samples-dotnet/blob/f281d33286bee85bb4740eee701895056ab4f5c4/src/Polling/PeriodicSequence/Program.cs#L34-L35>

to register several workflows to the same workers

Antonio

---

<div class="post-metadata">

**Author:** ![OhMyDeera](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/ohmydeera/32/5722_2.png) [@OhMyDeera](https://community.temporal.io/u/OhMyDeera)\
**Post date:** [August 8, 2024, 2:23pm UTC](https://community.temporal.io/t/triggering-a-workflow-on-another-service-from-a-workflow-activity/13109/6 "2024-08-08T14:23:11Z")

</div>

So specifying the task queue means that it will look in that queue in temporal for a worker? I had the queues in both services set to the same name. Changing them to be different and specifying the queue seemed to do the trick.

> [temporalio/samples-dotnet/blob/f281d33286bee85bb4740eee701895056ab4f5c4/src/Polling/PeriodicSequence/Program.cs#L34-L35](https://github.com/temporalio/samples-dotnet/blob/f281d33286bee85bb4740eee701895056ab4f5c4/src/Polling/PeriodicSequence/Program.cs#L34-L35)

Here it adds the Workflow to the service collection, but if the workflow doesn’t exist in the service collection, how would you add it? Would you register an interface to the service collection and then use that when calling the child service?

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [August 8, 2024, 3:00pm UTC](https://community.temporal.io/t/triggering-a-workflow-on-another-service-from-a-workflow-activity/13109/7 "2024-08-08T15:00:51Z")

</div>

Hi @OhMyDeera

> So specifying the task queue means that it will look in that queue in temporal for a worker?

Specifying the taskqueue will schedule the child workflow in the taskqueue that you specify, in the temporal server. If you don’t specify it the taskqueue name will be the same as the parent workflow.

> Here it adds the Workflow to the service collection, but if the workflow doesn’t exist in the service collection, how would you add it? Would you register an interface to the service collection and then use that when calling the child service?

You register workflow implementations to the worker, so the worker knows the code it has to run when it pulls a workflowTask. If you have time, take a look at one of this courses that explain how it works [Temporal 101: Introducing the Temporal Platform | Learn Temporal](https://learn.temporal.io/courses/temporal_101/)

Antonio
