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;
}
}