Question

J'ai ce code qui fonctionne dans un test unitaire, mais ne fonctionne pas lorsqu'il est exécuté dans le cadre d'un plug-in. Qu'est-ce que le code n'est d'essayer de créer une avance en appelant le webservice CRM4.

Lorsque le plugin exécute je reçois l'exception suivante: "état HTTP 401: Non autorisé"

Ceci est le code qui initialise une instance du webservice

CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = GetConfig("crm.organisation_name");
_crmService = new CrmService(GetConfig("webservice.crm"));

_crmService.CrmAuthenticationTokenValue = token;
_crmService.UseDefaultCredentials = false;                  
_crmService.PreAuthenticate = false;
_crmService.Credentials = new NetworkCredential(GetConfig("crm.user_username"),
                                                GetConfig("crm.user_password"), 
                                                GetConfig("crm.user_domain"));

Quelqu'un a des conseils sur ce que je peux essayer la prochaine? Le plomb est créé lorsque le test fonctionne, et les informations de configuration est la même dans le test unitaire comme lorsque l'application est en cours d'exécution du plug-in.

Était-ce utile?

La solution

Au lieu de l'instanciation CrmService par vous-même, sinon, vous pouvez obtenir le CrmService en obtenant la référence du IPluginExecutionContext et invoquer la méthode CreateCrmService

S'il vous plaît se référer à cette en ce qui concerne la création du CrmService de IPluginExecutionContext

Here is some code snippet

public void Execute(IPluginExecutionContext context)
{
  // the below code means, the CrmService will be created 
  // by referring to the user account who is registered to 
  // run the CRM Application Pool
  ICrmService crmService = context.CreateCrmService(false);

  // the below code means, the CrmService will be created
  // by taking account the user account who login and run
  // the current plugin
  ICrmService crmService = context.CreateCrmService(true);

  // the below code means, the CrmService will be created
  // by impersonating a valid user
  ICrmService crmService = context.CreateCrmService(new Guid("3F2504E0-4F89-11D3-9A0C-0305E82C3301"));
}

Cordialement,

hadi

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top