1) References
We no longer use the
Microsoft.Crm.* DLLs, as the namespace had a complete makeover. MS CRM 2011
introduced a brand new namespace “XRM”, hence the DLLs to use are
Microsoft.Xrm.*
Since the changes in MS CRM 2011
SDK are using WCF based services (compared to the web services used by its
predecessor), we must reference the below mentioned:
o System.ServiceModel
o
System.Runtime.Serialization
A reference to the
“Microsoft.IdentityModel” DLL is a must if the plugin is targeted at MS CRM
2011 online version.
2) Executing
Execute method now uses
IServiceProvider.
|
CRM 4.0
|
CRM 2011
|
public void
Execute(IPluginExecutionContext context)
|
public void
Execute(IServiceProvider serviceProvider)
|
3) IPluginExecutionContext
Similar to the “Execute” method
retrieving the context object inside a plugin also changed:
IPluginExecutionContext context =
(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
4) CRM Service
In CRM 2011,
ICrmService is replaced by IOrganizationService
5) DynamicEntity has
been changed to Entity
Similarly “Properties” of a CRM
entity now have to be accessed using the “Attribute” collection:
entity.Attributes.Contains("new_incidentnumber")
|
Below given template can be used to
create a plugin for the MS CRM 2011
using System; using System.ServiceModel; using System.Runtime.Serialization; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Sdk.Messages;
namespace MyPlugin
{ public class MyPlugin : IPlugin { public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity entity = (Entity)context.InputParameters["Target"]; if (entity.LogicalName != "entity logical name”) { return; } try { IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = factory.CreateOrganizationService(context.UserId); //Plugin Code } catch (FaultException ex) { throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex); } } } } } |
No comments:
Post a Comment