2017-10-13 9 views
0

CRM에서 글로벌 작업이 있습니다. 하나의 입력 문자열 매개 변수가 있습니다.MS Dynamics CRM에서 C# 글로벌 작업 호출

상태 코드 : 400 이 요청

obj.CallActivity("this is parameter string","MyActionName") 

를 보내는 전화 내 방법 요청을 실행할 때이

public async Task<bool> CallActivity(string record, string Activity) 
     { 
      try 
      { 

       HttpRequestMessage requestMessage = null; 
       requestMessage = new HttpRequestMessage(HttpMethod.Post, App.ResourceUri + "/api/data/v8.2/" + Activity); //uri to activity 
       requestMessage.Content =new StringContent(record); 
       requestMessage.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); 
       //Send the HttpRequest 
       Task<HttpResponseMessage> response = httpClient.SendAsync(requestMessage); 
        response.Wait(); 
       //If the response is Successfully executed then it will return the value true 
       if (response.Result.IsSuccessStatusCode) 
       { 
        return true; 
       } 
       else 
       { 
        return false; 
       } 
      } 
      catch (Exception error) 
      { 

       return false; 
      } 
     } 

과 같은 CallActivity, 내가 메시지를 얻을 , ReasonPhrase : '잘못된 요청', 버전 : 1.1, 내용 : System.Net.Http.StreamContent, 헤더 :

어디서 실수합니까?

+0

실제 매개 변수 값을 추가 할 수 있습니까? 오류는 문자열 매개 변수'Activity'가 작성되는 방식에서 매우 가능성이 있습니다. – Filburt

+0

obj.CallActivity ("{"id_contact ":"452e368a-1783-e711-8102-70106faa95f1 ","id_car ":"45436d5b-d19d-e711-8101-70106faa5221 "}", "MyActionName"). 입력 문자열 매개 변수는 JSON 문자열과 같아야합니다. – user238271

+0

"MyActionName"은 게시자 접두어와 액션 스키마 이름으로 구성되어 있으므로 문제가되지 않습니다. 그러나 O-Data 버전 헤더는 설정하지 않습니다. 나는 웹 API가 이것에 대해 흔들리는 것을 보았 기 때문에' "OData-MaxVersion", "4.0"'과''OData-Version ','4.0 ''헤더를 추가하려고 할 수있다. – Filburt

답변

0

아래는 내 Action from Plugin을 호출하는 데 사용하는 코드입니다.

송신자관련 문의은 내 작업의 두 매개 변수이며이 기능은 정상적으로 작동합니다.

OrganizationRequest req = new OrganizationRequest("crmp_emailbenachrichtigunganeventowner468fcc7975b9e71180e6005056936953"); 

         req["Sender"] = new EntityReference(temp.GetAttributeValue<EntityReference>("ownerid").LogicalName, temp.GetAttributeValue<EntityReference>("ownerid").Id); 

         req["regardingcontact"] = new EntityReference(context.PrimaryEntityName, context.PrimaryEntityId); 
         OrganizationResponse response = service.Execute(req);