C#在MS Dynamics CRM中调用全局操作

时间:2017-10-13 11:24:05

标签: c# dynamics-crm crm

我在CRM中有全局行动。它有一个输入字符串参数。 这是要求发送请求

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

和我的方法 CallActivity 看起来像这样

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;
            }
        }

执行请求时,我收到消息:

  

StatusCode:400,ReasonPhrase:'错误请求',版本:1.1,内容:System.Net.Http.StreamContent,标题:

我在哪里犯错?

1 个答案:

答案 0 :(得分:0)

以下是我用来从插件中调用Action的代码。

发件人有关联系是我的操作的两个参数,这对我来说很好。

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);