当在“Dynamics CRM Online”中创建联系人时,我们正在尝试将数据推送到 Azure 服务总线队列。我们通过使用插件注册工具注册插件来实现它。但不知何故,它在保存联系人时抛出了一个错误。这是我们在插件中实现的代码:
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;
}
}