locked
Push data to servicebus when a contact is created - CRM Online RRS feed

  • Question

  • We are trying to push data to Azure Service Bus Queue when a contact is created in "Dynamics CRM Online".

    We have implemented it using a plugin by registering it with Plugin Registration Tool. But somehow its throwing an error while saving the contact. Here is the code which we have implemented in plugin:

    public void Execute(IServiceProvider serviceProvider)
        {
            try
            {                
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                Entity entity = (Entity)context.InputParameters["Target"];
                if (entity.LogicalName.Equals("account"))
                {
                    QueueDescription qd = new QueueDescription("testQ");
    
                    qd.MaxSizeInMegabytes = 5120;
                    qd.DefaultMessageTimeToLive = new TimeSpan(0, 1, 0);
    
                    string connectionString =
                        CloudConfigurationManager.GetSetting("Endpoint=sb://test.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=secretcode=");
    
                    var namespaceManager =
                        NamespaceManager.CreateFromConnectionString(connectionString);
                    if (!namespaceManager.QueueExists("testQ"))
                    {
                        namespaceManager.CreateQueue("testQ");
                    }
    
                    QueueClient Client =
                        QueueClient.CreateFromConnectionString(connectionString, "testQ");
    
                    BrokeredMessage message = new BrokeredMessage(entity);
    
                    message.Properties["FirstName"] = "ABC";
                    message.Properties["LastName"] = "Z";
    
                    Client.Send(message);
                }
            }
            catch (Exception e)
            {
                throw;
            }
    }

    Error message:

    Business Process Error

    Unexpected exception from plug-in (Execute): Microsoft.Crm.Sdk.Samples.Account: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.ServiceBus, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified


    Friday, November 1, 2013 12:14 PM