0

Good day to ya all!.

I am coding for Dynamics CRM for a while and now I need to make a special program for it. I am thinking of leveraging workflows and a windows service.

In my architecture, whenever a specific workflow runs, it creates an "object creation request" record in CRM. A windows service residing on the same server, must be notified of this object, come to load it, process it and put the result back in the CRM.

The question remains here. whenever a record is created, Should I ...

  1. Call my windows service from a plugin or workflow using wcf or
  2. Make my windows service to pull data every few seconds for new records.

In either choices, any ideas is warmly appreciated. Thanks guys.

Mohfath
  • 57
  • 1
  • 11

1 Answers1

1

I would not use either of these approaches.

I would use Microsoft Message Queue (MSMQ) to handle the communication. MSMQ is available for install on Windows Server.

The plugin should place a message in a queue.

The windows service should listen for messages on the queue and process them when received.

There is extensive documentation on using MSMQ from C# available online but here is the bare minimum:

//Send Message
MessageQueue messageQueue = null;
if (MessageQueue.Exists(@".\Private$\SomeTestName"))
{
    messageQueue = new MessageQueue(@".\Private$\SomeTestName");
    messageQueue.Label = "Testing Queue";
}
else
{
    // Create the Queue
    MessageQueue.Create(@".\Private$\SomeTestName");
    messageQueue = new MessageQueue(@".\Private$\SomeTestName");
    messageQueue.Label = "Newly Created Queue";
}
messageQueue.Send("First ever Message is sent to MSMQ", "Title");

//Receive Message
MessageQueue messageQueue = new MessageQueue(@".\Private$\SomeTestName");
System.Messaging.Message[] messages = messageQueue.GetAllMessages();

foreach (System.Messaging.Message message in messages)
{
    //Do something with the message.
}
// after all processing, delete all the messages
messageQueue.Purge();

The reason to do this is that it decouples the plugin and the windows service and it eliminates the need to constantly poll CRM for records.

Nicknow
  • 7,154
  • 3
  • 22
  • 38
  • +1 up for your great answer. Points and pros you mentioned seem great, I will test it to see if I am able to use this in a CRM plugin (since it is an isolated location) and inform you. Till then, let's wait for other people's opinion. – Mohfath Jan 16 '18 at 06:03
  • @Mohfath do you mean you are running the plugin in isolation/sandbox mode? If so, why do that for an on-premises plug-in? – Nicknow Jan 16 '18 at 06:47
  • The solution worked Perfectly and nicely. For everyone visiting this page and using this method, I just remind you to give your queue, correct permissions so CRM can access them. – Mohfath Jan 16 '18 at 08:21