Fehler 401 Aufruf crm4 webservice
-
21-08-2019 - |
Frage
Ich habe diesen Code, der in einem Unit-Test funktioniert, aber funktioniert nicht, wenn im Rahmen eines Plugins ausgeführt. Was der Code tut, ist zu versuchen, eine Führung zu schaffen, indem die crm4 Webservice aufgerufen wird.
Wenn das Plugin ausführt ich die folgende Ausnahme erhalten: "HTTP-Status 401: Unauthorized"
Dies ist der Code, der eine Instanz des Webservice initialisiert
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"));
Wer noch Ratschläge, was ich als nächstes versuchen kann? Die Leitung wird erstellt, wenn der Test läuft, und die Konfigurationsinformationen die gleiche ist in der Unit-Test, wie es ist, wenn die Anwendung das Plugin ausgeführt wird.
Lösung
Rather die CrmService selbst als instanziiert wird, alternativ können Sie die CrmService erhalten, indem die Referenz des IPluginExecutionContext zu erhalten und die CreateCrmService Methode aufrufen
Bitte auf diese Link rel="nofollow über den CrmService von IPluginExecutionContext Schaffung
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"));
}
Grüße,
hadi