0

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;
        }
}
  • please add also the error message – Guido Preite Oct 28 '13 at 07:39
  • **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. – user2926841 Oct 28 '13 at 10:35
  • Are you using a tool like ILMerge to to merge all the dlls you have referenced? – Andy Meyers Oct 28 '13 at 13:38
  • Yep. we have tried it but didn't work! – user2926841 Oct 30 '13 at 13:32

2 Answers2

0

How are you referencing the DLL? You must add a local reference (not GAC). Eg: C:\Program Files (x86)\Windows Azure platform AppFabric SDK\V1.0\Assemblies\NET4.0\Microsoft.ServiceBus.dll

Also, set "Copy Local" to true so that the assembly is packaged with your plugin.

Sunil
  • 624
  • 4
  • 10
  • i have added service bus dll through NuGet. i have tried adding appfabric servicebus dll. it doesn't contain CreateFromConnectionString method. – user2926841 Oct 29 '13 at 07:14
  • Download the SDK from here and add the references manually. http://www.windowsazure.com/en-us/downloads/?fb=en-us The NuGet package could be missing the assembly. – Sunil Oct 29 '13 at 12:22
  • the above link sdk doesn't contain servicebus.dll. we already tried it. Is der any other solution to push data out from CRM Online? – user2926841 Oct 30 '13 at 13:31
  • Sorry, you should be able to find the dll in the App Fabric SDK http://www.microsoft.com/en-us/download/details.aspx?id=19925 – Sunil Nov 13 '13 at 20:28
0

You should look at the Dynamics CRM 2013 SDK examples at \SDK\SampleCode\CS\Azure If you haven't been updated to going to assume you've been upgraded to the Fall ’13 release you should look at the same location in the Dynamics CRM 2011 SDK. It won't work exactly as you have it - but you can meet all you requirements using the supported method.

You need to use the Azure Plugin functionality that is in Dynamics CRM. I would add the details but they are too long and best read with the pictures: http://blogs.msdn.com/b/crm/archive/2011/02/18/windows-azure-appfabric-integration-with-microsoft-dynamics-crm-step-by-step.aspx

Nicknow
  • 7,154
  • 3
  • 22
  • 38