Hi, i have 10 plugins (has external dlls) in my dynamics 365 crm on-premise ,so with some tedious unknown reasons, sometime not working and sometime work and that's make me to find another way to handle my flow. in first step find out we have feature call webhooks but i can't find any source to work with on-premise version of dynamics 365 crm and every tutorial work with Azure Function, which is worked in cloud. after few search i decided to create local host web api and call it from plugin registration and handle my flow by external webapi.
I created simple web api by .net core 3.1 and host in "">https://localhost::44379" and created below plugin:
namespace SampleWorkflowActivity
{
public class IncrementByTen : CodeActivity
{
[RequiredArgument]
[Input("Decimal Input")]
public InArgument DecInput { get; set; }
[Output("Decimal Output")]
public OutArgument DecOutput { get; set; }
protected override void Execute(CodeActivityContext context)
{
decimal input = DecInput.Get(context);
var request = (HttpWebRequest)WebRequest.Create("https://localhost:44379/weatherforecast");
request.UseDefaultCredentials = true;
request.Method = "GET";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
request.ContentType = "application/json; charset=utf-8";
var response = (HttpWebResponse)request.GetResponse();
using (Stream responseStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
DecOutput.Set(context, reader.ReadToEnd());
}
}
}
}
when case created this workflow executed and call my API and process something and put my result inside "DecOutput" .
my plugin register without any error but when try to call my api give me below error:
Workflow suspended temporarily due to error: Unhandled Exception: System.Net.WebException: Unable to connect to the remote server
at System.Net.HttpWebRequest.GetResponse()
at SampleWorkflowActivity.IncrementByTen.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Inner Exception: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:44379
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
Note: i try same code with different api- "">https://reqres.in/api/users" (in internet instead of localhost) and worked fine.