Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65391

Calling web services from a CRM Plugin

We are designing a system where the business calculations will be encapsulated in CRM plugins which are called from a workflow in CRM.

Many of these business calculations are in legacy systems in several different technologies.

Question is: Do we have to move this code into the plugin as C# code, or can we call it via a web service from the Plugin?

Upvotes: 0

Views: 2441

Answers (3)

Caleb Bell
Caleb Bell

Reputation: 524

You mentioned that the plugins would be "called from a workflow in CRM", which might mean a few different things:

  1. You've registered a Plug-In on a particular entity/message, and a workflow will cause that message to fire, thus invoking your Plug-In.
  2. You've registered a Custom Workflow Activity, and you're going to invoke this as a step within a workflow.

You have a few different options for storing the configuration information (e.g. the service endpoint URL, etc.):

  1. Hard-code this data in the assembly.
  2. Create a configuration entity in CRM and retrieve the appropriate configuration record(s) at run-time using the CRM web service (i.e. an IOrganizationService instance from the context).
  3. Create a custom Action in CRM that returns the configuration information (link).
  4. For a plug-in, pass the configuration information to the plug-in's constructor by adding the information to the "Unsecure Configuration" or "Secure Configuration" steps in the registration for the plug-in assembly's steps via the Plugin Registration tool.
  5. For a Custom Workflow Activity, pass the configuration information to the activity via an InParameter argument.

There are pros and cons to each of these approaches that depend on a variety of factors that are dependent upon your scenario:

  • How do you handle other bits of configuration information in your deployment?
    • If you already use a configuration entity or custom Action, it might be more preferable to add a new field there rather than "hiding" the configuration information in a plug-in's registration steps (and vice versa).
  • How will the configuration information change across different environments/organizations?
    • If the configuration is static and will "never" need to be modified, then you could hard-code it into the assembly.
    • If the configuration is static and you're using a plug-in, then you can put the information into the plug-in's registration, and it can be migrated as part of a solution.
  • Which version of CRM are you using?
    • Custom Actions are only available from CRM 2013 onwards.
  • Does the solution need to work in offline scenarios?
    • Custom Actions may not work in such scenarios.
  • How many different plug-in steps need to be registered? / How many Processes will use the custom workflow activity?
    • If there are many, then it may become unmaintainable to specify the information in each place where it is needed and a configuration entity/Action might be preferable.
  • Who will have access to (and who will need to) modify the configuration information?
    • If you're using a custom activity and non-technical business users have access to modify the workflows that use the activity, then you might not want to pass the information as a parameter to the activity (due to the possibility of introducing user error).
  • What is the performance profile of the plug-in/custom activity?
    • If you want maximum performance, then you may not want the overhead of retrieving the configuration information from a custom entity or action.

Etc.

Upvotes: 0

Christian V
Christian V

Reputation: 2040

A custom workflow plugin is a Windows Workflow Foundation activity. Whatever you can do in a workflow activity you can do as a workflow plugin - so, the answer is yes. However, you may want to give configuration parameters as input to the workflow activity (ie. the URL to the service) or store it in a custom entity. This way everything can be configured from CRM. You can even export the workflow xaml, modify it in a designer and reimport it into CRM. In CRM 2011 this is even a supported approach (so they say). Note that for CRM online, custom workflow activities are not supported.

Upvotes: 2

Pradeep
Pradeep

Reputation: 3276

You can call web services from plugin and then call these plugins from workflow. It has been many years since I touched CRM but I used to do it and there should not be any problem.

Upvotes: 1

Related Questions