.net core workflow

Hi Team,

I have created two work flows independent dot net core solutions,

  1. Email notification and
  2. SMS notification

Then I have created another dot net core solution for api
This api accept notification type(“SMS”,“EMAIL”) based on this type, I need to call my above mentioned workflow.
With out reference workflows dll, I need to call these workflow in API controller, Please help me how I call and do you have sample>

Using a Temporal client, there are overloads for StartWorkflowAsync and ExecuteWorkflowAsync to pass the string name of the workflow to call and the arguments. You don’t have to have the workflow definitions present.

Thank you so much for your quick response!!!

I used ExecuteWorkflowAsync but I am getting error arguments
“2024-12-03T04:54:51.230714Z WARN temporal_sdk_core::worker::workflow: Failing workflow task run_id=ef918921-fe22-4c28-a117-e64cdc1bdfb1 failure=Failure { failure: Some(Failure { message: “Workflow SmsNotificationWorkflow had failure decoding parameters”, source: “”, stack_trace: " at Temporalio.Worker.WorkflowInstance.DecodeArgs(MethodInfo method, IReadOnlyCollection1 payloads, String itemName, Boolean dynamic, String dynamicArgPrepend)\r\n at Temporalio.Worker.WorkflowInstance.<>c__DisplayClass45_1.<.ctor>b__7()\r\n at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode)\r\n at System.Lazy1.CreateValue()\r\n at Temporalio.Worker.WorkflowInstance.get_Instance()\r\n at Temporalio.Worker.WorkflowInstance.<ApplyStartWorkflow>b__158_1()\r\n at Temporalio.Worker.WorkflowInstance.RunTopLevelAsync(Func1 func)\r\n at Temporalio.Worker.WorkflowInstance.RunOnce(Boolean checkConditions)\r\n at Temporalio.Worker.WorkflowInstance.Activate(WorkflowActivation act)”, encoded_attributes: None, cause: Some(Failure { message: “The JSON value could not be converted to SmsNotificationWorkflow.Contracts.SmsNotificationRquest. Path: $ | LineNumber: 0 | BytePositionInLine: 6.”, source: “”, stack_trace: " at System.Text.Json.ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(Type propertyType)\r\n at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)\r\n at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)\r\n at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)\r\n at System.Text.Json.Serialization.Metadata.JsonTypeInfo1.DeserializeAsObject(Utf8JsonReader& reader, ReadStack& state)\r\n at System.Text.Json.JsonSerializer.ReadFromSpanAsObject(ReadOnlySpan1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable1 actualByteCount)\r\n at System.Text.Json.JsonSerializer.Deserialize(ReadOnlySpan1 utf8Json, Type returnType, JsonSerializerOptions options)\r\n at Temporalio.Converters.JsonPlainConverter.ToValue(Payload payload, Type type)\r\n at Temporalio.Converters.DefaultPayloadConverter.ToValue(Payload payload, Type type)\r\n at Temporalio.Worker.WorkflowInstance.<DecodeArgs>b__163_0(Payload payload, ParameterInfo paramInfo)\r\n at System.Linq.Enumerable.ZipIterator[TFirst,TSecond,TResult](IEnumerable1 first, IEnumerable1 second, Func3 resultSelector)+MoveNext()\r\n at System.Collections.Generic.List1.AddRange(IEnumerable1 collection)\r\n at Temporalio.Worker.WorkflowInstance.DecodeArgs(MethodInfo method, IReadOnlyCollection`1 payloads, String itemName, Boolean dynamic, String dynamicArgPrepend)“, encoded_attributes: None, cause: None, failure_info: Some(ApplicationFailureInfo(ApplicationFailureInfo { r#type: “JsonException”, non_retryable: false, details: None, next_retry_delay: None })) }), failure_info: Some(ApplicationFailureInfo(ApplicationFailureInfo { r#type: “InvalidOperationException”, non_retryable: false, details: None, next_retry_delay: None })) }), force_cause: Unspecified }”

Below is the code for calling from client

if (request.Type.Equals(“SMS”, StringComparison.OrdinalIgnoreCase))
{
var smsNotification = NotificationMapping.MapToSmsNotificationRequest(request);
var sms = new SmsNotificationWorkflow.Contracts.SmsNotificationRquest { Message = smsNotification.Message, PhoneNumber = smsNotification.PhoneNumber };
//var smsWorkflow = client.ExecuteWorkflowAsync(
// (SmsNotificationWorkflow.SmsNotificationWorkflows.SmsNotificationWorkflow wf) => wf.RunAsync(sms),
// new(id: Guid.NewGuid().ToString(), taskQueue: “SMS_NOTIFICATION_TASK_QUEUE”));
List smsValue = new List();

smsValue.Add(sms.Message);
smsValue.Add(sms.PhoneNumber);                  

ReadOnlyCollection<string> readOnlySms =
    new ReadOnlyCollection<string>(smsValue);

var smsWorkflow = client.ExecuteWorkflowAsync(
    "SmsNotificationWorkflow",
   readOnlySms,
    new(id: Guid.NewGuid().ToString(), taskQueue: "SMS_NOTIFICATION_TASK_QUEUE"));
return Ok();

}

Workflow

[Workflow]
public class SmsNotificationWorkflow
{
[WorkflowRun()]
public async Task RunAsync(SmsNotificationRquest smsRequest)
{
Console.WriteLine(“Sms Notification Workflow started…”);
// Retry policy
var retryPolicy = new RetryPolicy
{
InitialInterval = TimeSpan.FromSeconds(1),
MaximumInterval = TimeSpan.FromSeconds(100),
BackoffCoefficient = 2,
MaximumAttempts = 3,
};
string smsEmailResult;
try
{
smsEmailResult = await Workflow.ExecuteActivityAsync(
() => SmsNotificationActivities.EmailNotificationActivities.SendSmsAsync(smsRequest),
new ActivityOptions { StartToCloseTimeout = TimeSpan.FromMinutes(5), RetryPolicy = retryPolicy }
);
Console.WriteLine(“Sms Notification Workflow completed…”);
return $“Sms Notification Workflow completed {smsEmailResult})”;
}
catch (ApplicationFailureException ex)
{
throw new ApplicationFailureException(“Failed due to sent sms.”, ex);
}
}
}

Please suggest how can I fix this issue.