Modifying the SAS key for Service Endpoint from c# script CRM

Viewed 185

I have Service Endpoint for D365 (CRM online) to connect with Azure Service Bus during registration I've specified SAS key from Service Bus Queue and everything works as expected.

Currently, I need to modify the SAS key for some environments but I would prefer to do it from c# script to avoid manual actions. During the investigation, I've found out service endpoint info in the entity "serviceendpoint" and SAS key should be in the "authvalue" field. I'm trying to perform a regular update for this field but no lack. For some reason, it is impossible to perform a regular update for it.

Could anybody share ideas on how to update the SAS key from the c# script?

1 Answers

I know this comes a little late but I found myself in this exact situation and this is working for me:

// get the CRM endpoints
var query = new QueryExpression("serviceendpoint");
query.ColumnSet.AddColumns("name", "serviceendpointid", "saskeyname");
query.Criteria.AddCondition("name", ConditionOperator.EndsWith, busName);

var queryResult = client.RetrieveMultiple(query);
foreach (var entity in queryResult.Entities)
{
    var updateEntity = new Entity(entity.LogicalName, entity.Id);
    updateEntity["namespaceaddress"] = nameSpace;
    updateEntity["saskeyname"] = sasName;
    updateEntity["saskey"] = sasKey;
    client.Update(updateEntity);
}

Partly working because I don't get an error and I can see the saskeyname attribute changing on the Plugin Registration Tool, but then the endpoint stops sending data. I then overrode it with the key on that same tool and it worked again, so from what I can see I can update the values but there's something special about that field I just couldn't find anything on the documentation.

Hope this helps someone, and if anyone knows what I'm missing please just let me know

Related