오류 401 호출 CRM4 웹 서비스
-
21-08-2019 - |
문제
단위 테스트에서 작동하지만 플러그인의 맥락에서 실행될 때 작동하지 않는이 코드가 있습니다. 코드가하는 일은 CRM4 웹 서비스를 호출하여 리드를 작성하는 것입니다.
플러그인이 실행되면 다음과 같은 예외가 발생합니다. "HTTP 상태 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를 직접 인스턴스화하는 대신 iPluginexecutionContext의 참조를 얻어 CreateCrmservice 방법을 호출하여 crmservice를 얻을 수 있습니다.
이것을 참조하십시오 링크 ipluginexecutionContext에서 crmservice 생성에 관한 것입니다
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"));
}
문안 인사,
하디
제휴하지 않습니다 StackOverflow