web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Call Web Api via registered plugin

(0) ShareShare
ReportReport
Posted on by 355

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.

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I believe your plugin doesn't work because you use url with "localhost" that is not valid name for the plugin.

    You should get the same result if you try to access your api by the IP. Try to use real name of the server and it should work fine.

  • Suggested answer
    Lixzh Profile Picture
    on at

    Hi,I suggest using the server name to try again. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
iampranjal Profile Picture

iampranjal 77

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 43 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans