【问题标题】:MS Dynamics 365 Online Plugin External Rest API access gives errorMS Dynamics 365 Online Plugin External Rest API 访问给出错误
【发布时间】:2020-08-16 22:24:56
【问题描述】:

我正在尝试使用以下代码从 Dynamics 365 Online 插件访问外部第三方 API:

public void Execute(IServiceProvider serviceProvider)
    {
        //Extract the tracing service for use in plug-in debugging.
        ITracingService tracingService = 
            (ITracingService)serviceProvider.GetService(typeof(ITracingService));

        try
        {
            tracingService.Trace("Downloading the target URI: " + webAddress);

            try
            {
                //<snippetWebClientPlugin2>
                // Download the target URI using a Web client. Any .NET class that uses the
                // HTTP or HTTPS protocols and a DNS lookup should work.
                using (WebClient client = new WebClient())
                {
                    byte[] responseBytes = client.DownloadData(webAddress);
                    string response = Encoding.UTF8.GetString(responseBytes);
                    //</snippetWebClientPlugin2>
                    tracingService.Trace(response);

                    // For demonstration purposes, throw an exception so that the response
                    // is shown in the trace dialog of the Microsoft Dynamics CRM user interface.
                    throw new InvalidPluginExecutionException("WebClientPlugin completed successfully.");
                }
            }

            catch (WebException exception)
            {
                string str = string.Empty;
                if (exception.Response != null)
                {
                    using (StreamReader reader = 
                        new StreamReader(exception.Response.GetResponseStream()))
                    {
                        str = reader.ReadToEnd();
                    }
                    exception.Response.Close();
                }
                if (exception.Status == WebExceptionStatus.Timeout)
                {
                    throw new InvalidPluginExecutionException(
                        "The timeout elapsed while attempting to issue the request.", exception);
                }
                throw new InvalidPluginExecutionException(String.Format(CultureInfo.InvariantCulture,
                    "A Web exception occurred while attempting to issue the request. {0}: {1}", 
                    exception.Message, str), exception);
            }
        }
        catch (Exception e)
        {
            tracingService.Trace("Exception: {0}", e.ToString());
            throw;
        }
    }
}

但我得到了错误:

Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.'

我检查了 MS 文档,但没有任何迹象表明我无法执行此操作。我知道沙盒插件,但根据 MS,我应该能够使用他们自己的示例代码来做到这一点。

【问题讨论】:

  • 我的回答有帮助吗?

标签: plugins dynamics-crm dynamics-crm-online dynamics-crm-365


【解决方案1】:

这在 CRM Online 中是预期的,因为这是 SaaS,并且您在云中的共享租户中。您可以执行 webhook 或 Azure 服务中心,以触发具有 CRM 上下文的外部端点进行处理。 Read more

如果您拥有 CRM Online,那么通常的解决方案是将处理工作转移到您可以更好地控制的环境中。最常见的选项是使用 Azure Service Bus or Azure Event Hub 将处理卸载到 Azure。 CRM 9 新增的替代方法是将数据发送到 WebHook,您可以将其托管在您喜欢的任何地方。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-09
    • 2020-05-28
    • 2020-01-17
    • 1970-01-01
    • 2019-10-23
    • 1970-01-01
    • 2016-03-11
    • 2018-02-07
    相关资源
    最近更新 更多