خطأ 401 استدعاء CRM4 WebService
-
21-08-2019 - |
سؤال
لديّ هذا الرمز الذي يعمل في اختبار الوحدة ولكنه لا يعمل عند تنفيذه في سياق البرنامج المساعد. ما يفعله الرمز هو محاولة إنشاء تقدم عن طريق الاتصال بـ CRM4 WebService.
عند تنفيذ المكون الإضافي ، أحصل على الاستثناء التالي: "HTTP Status 401: غير مصرح به"
هذا هو الرمز الذي يميز مثيل خدمة الويب
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"));
أي شخص لديه نصيحة بشأن ما يمكنني تجربته بعد ذلك؟ يتم إنشاء الرصاص عند تشغيل الاختبار ، ومعلومات التكوين هي نفسها في اختبار الوحدة كما هو الحال عندما يقوم التطبيق بتنفيذ المكون الإضافي.
المحلول
بدلاً من إنشاء إنشاء Crmservice بنفسك ، يمكنك بدلاً من ذلك الحصول على Crmservice عن طريق الحصول على مرجع iPluginexecutionContext واستدعاء طريقة Createcrmservice
يرجى الرجوع إلى هذا حلقة الوصل فيما يتعلق بإنشاء crmservice من 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"));
}
يعتبر،
هادي