This documentation is archived and is not being maintained.

RegisterSolution Message (CrmService)

Forefront
banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment typesWorks online only

Registers a plug-in or custom workflow activity assembly.

The relevant classes are specified in the following table.

TypeClass
RequestRegisterSolutionRequest
ResponseRegisterSolutionResponse
Optional ParametersDoes not apply to this message.

Remarks

Note that a pre-image on a Create message and a post-image on a Delete message are not supported. This is because the entity does not exist at that stage in the execution pipeline.

To use this message, pass an instance of the RegisterSolutionRequest class as the request parameter in the Execute method.

For a list of required privileges, see RegisterSolution Privileges.

Example

The following code example shows you how to register a plug-in.

[C#]
// Set up the CRM service.
CrmAuthenticationToken token = new CrmAuthenticationToken();

// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle";
 
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Get the plug-in assembly.
Assembly dll = Assembly.LoadFile(assemblyFileLocation);

// Create the plug-in assembly.  
pluginassembly assem = new pluginassembly();
assem.name = dll.GetName().Name;
assem.sourcetype = new Picklist();

// Note: SourceType 0 is "Database".
assem.sourcetype.Value = 0;  
assem.culture = dll.GetName().CultureInfo.ToString();
assem.version = dll.GetName().Version.ToString();

Byte[] tokenBytes = dll.GetName().GetPublicKeyToken();
StringBuilder builder = new StringBuilder(32);
foreach (byte b in tokenBytes)
{
    builder.Append(b.ToString("x").PadLeft(2, '0'));
}
assem.publickeytoken = builder.ToString();

// Load the file into pluginassembly.content.
FileInfo fi = new FileInfo(dll.Location);
using (FileStream fs = File.OpenRead(dll.Location))
{
   byte[] buffer = new byte[fi.Length];
   fs.Read(buffer, 0, (int)fi.Length);
   int outputSize = (int)Math.Ceiling(fi.Length / 3d) * 4;
   char[] output = new char[outputSize];
   System.Convert.ToBase64CharArray(buffer, 0, buffer.Length, output, 0);
   assem.content = new string(output);
}
 
// Create registration steps. 
SdkMessageProcessingStepRegistration step = new SdkMessageProcessingStepRegistration();
step.MessageName = "Create";
step.PrimaryEntityName = "account";

// Note: Stage 10 = BeforeMainOperationOutsideTransaction.
step.Stage = 10;

// Note: SupportedDeployment 0 = ServerOnly.
step.SupportedDeployment = 0;  
step.PluginTypeName = "Microsoft.Crm.Sdk.Plugin.HelloWorld";
step.PluginTypeFriendlyName = "Hello World Plug-in";
step.Description = "Changes account name to 'Hello World'";

// Note: Mode 0 = synchronous.
step.Mode = 0;  
SdkMessageProcessingStepRegistration[] steps = { step };
 
// Give the plug-in access to a post-image of the account's attributes.
SdkMessageProcessingStepImageRegistration image = new SdkMessageProcessingStepImageRegistration();
image.MessagePropertyName = "Id";

// Note: ImageType 1 = PostImage.
image.ImageType = 1; 
image.EntityAlias = "PostImage";
string[] attr = { "accountid", "name", "description", "emailaddress1" };
image.Attributes = attr;
SdkMessageProcessingStepImageRegistration[] images = { image };
step.Images = images;
 
//Create a register request.
RegisterSolutionRequest request = new RegisterSolutionRequest();
request.PluginAssembly = assem;
request.Steps = steps;

//Execute the register request.
RegisterSolutionResponse response = (RegisterSolutionResponse)service.Execute(request);
[Visual Basic .NET]
' Set up the CRM service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
 
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Get the plug-in assembly
Dim dll As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile(assemblyFileLocation)

' Create the plug-in assembly.
Dim assem As New pluginassembly()
assem.name = dll.GetName().Name
assem.sourcetype = New Picklist()

' Note: SourceType 0 is "Database".
assem.sourcetype.Value = 0
assem.culture = dll.GetName().CultureInfo.ToString()
assem.version = dll.GetName().Version.ToString()

Dim tokenBytes() As Byte = dll.GetName().GetPublicKeyToken()
Dim builder As New StringBuilder(32)
For Each b As Byte In tokenBytes
   builder.Append(b.ToString("x").PadLeft(2, "0"c))
Next b
assem.publickeytoken = builder.ToString()

' Load the file into pluginAssembly.content.
Dim fi As New FileInfo(dll.Location)
Using fs As FileStream = File.OpenRead(dll.Location)
   Dim buffer(fi.Length - 1) As Byte
   fs.Read(buffer, 0, CInt(Fix(fi.Length)))
   Dim outputSize As Integer = CInt(Fix(Math.Ceiling(fi.Length / 3R))) * 4
   Dim output(outputSize - 1) As Char
   System.Convert.ToBase64CharArray(buffer, 0, buffer.Length, output, 0)
   assem.content = New String(output)
End Using

' Create registration steps.
Dim [step] As New SdkMessageProcessingStepRegistration()
[step].MessageName = "Create"
[step].PrimaryEntityName = "account"

' Note: State 10 = BeforeMainOperationOutsideTransaction.
[step].Stage = 10

' Note: SupportedDeployment 0 = ServerOnly.
[step].SupportedDeployment = 0
[step].PluginTypeName = "Microsoft.Crm.Sdk.Plugin.HelloWorld"
[step].PluginTypeFriendlyName = "Hello World Plug-in"
[step].Description = "Changes account name to 'Hello World'"

' Note: Mode 0 = synchronous.
[step].Mode = 0
Dim steps() As SdkMessageProcessingStepRegistration = { [step] }

' Give the plug-in access to a post-image of the account's attributes.
Dim image As New SdkMessageProcessingStepImageRegistration()
image.MessagePropertyName = "Id"

' Note: ImageType 1 = PostImage.
image.ImageType = 1
image.EntityAlias = "PostImage"
Dim attr() As String = { "accountid", "name", "description", "emailaddress1" }
image.Attributes = attr
Dim images() As SdkMessageProcessingStepImageRegistration = { image }
[step].Images = images

'Create a register request.
Dim request As New RegisterSolutionRequest()
request.PluginAssembly = assem
request.Steps = steps

'Execute the register request.
Dim response As RegisterSolutionResponse = CType(service.Execute(request), RegisterSolutionResponse)

See Also

Concepts

Reference


© 2010 Microsoft Corporation. All rights reserved.


Show: