Plugins MS Dynamics 365联机插件外部Rest API访问出错

Plugins MS Dynamics 365联机插件外部Rest API访问出错,plugins,dynamics-crm,dynamics-crm-online,dynamics-crm-365,Plugins,Dynamics Crm,Dynamics Crm Online,Dynamics Crm 365,我正在尝试使用以下代码从Dynamics 365在线插件访问外部第三方API: public void Execute(IServiceProvider serviceProvider) { //Extract the tracing service for use in plug-in debugging. ITracingService tracingService = (ITracingService)serviceProv

我正在尝试使用以下代码从Dynamics 365在线插件访问外部第三方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;
        }
    }
}

我已经检查了MS文档,但没有任何迹象表明我为什么不能这样做。我知道沙盒插件,但根据微软的说法,我应该能够使用他们自己的示例代码来实现这一点。

这是CRM Online中所期望的,因为这是SaaS,您在云中的共享租户中。您可以使用webhook或Azure service hub触发具有CRM上下文的外部端点进行处理

如果您已经实现了CRM在线,那么通常的解决方案是将处理工作转移到您可以更好地控制的环境中。最常见的选择是使用。CRM 9新增的另一种方法是将数据发送到服务器,服务器可以托管在您喜欢的任何位置


我的回答有用吗?
Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.'