Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Using the Web Services within a Custom Workflow Activity

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

In order to call Web service methods, you must get a reference to the CrmService class or the MetadataService class. These classes are available using the following methods:

IWorkflowContext.CreateCrmService

IWorkflowContext.CreateMetadataService

Using the DynamicEntity Class in Plug-ins

It is strongly recommended that all custom workflow activities should retrieve, create, update, or delete data in Microsoft Dynamics CRM 4.0 using the DynamicEntity class. By using DynamicEntity, your code will work with out-of-the-box entity and attribute definitions and with any customizations you have made to entities or attributes.

Use of strong entity types from the Microsoft.Crm.SdkTypeProxy.dll assembly in any custom code is not supported. These types are deprecated and will be removed in a future SDK release.

For more information about DynamicEntity, see Using DynamicEntity to Access Entities at Runtime.

Example

The following sample code shows how to get the CrmService from within the Execute method of your custom workflow activity.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
   // Get the context service.
   IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
   IWorkflowContext context = contextService.Context;

   // Use the context service to create an instance of CrmService.
   ICrmService crmService = context.CreateCrmService();

   // Use the CrmService to call methods.
}

Example

The following sample code shows how to get the MetadataService from within the Execute method of your custom workflow activity.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
    IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
    IWorkflowContext workflowContext = contextService.Context;

    IMetadataService metadataService = workflowContext.CreateMetadataService();
    RetrieveEntityRequest req = new RetrieveEntityRequest();
    req.LogicalName = "account";
    RetrieveEntityResponse resp = (RetrieveEntityResponse)metadataService.Execute(req);

    myString = resp.EntityMetadata.PrimaryField;
    return base.Execute(executionContext);
}

See Also

Reference

Other Resources


© 2010 Microsoft Corporation. All rights reserved.


Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.