【问题标题】:Http request from dynamics crm 2016 custom workflow fails to certain urls来自动态 crm 2016 自定义工作流的 Http 请求无法访问某些 url
【发布时间】:2019-09-16 14:29:33
【问题描述】:

我需要从动态 crm 向 azure 函数 http 端点发出请求。 crm 是内部部署的 2016 实例。我想在自定义工作流/操作中执行此操作,因为我想在几个不同的地方触发操作(手动、来自 Web 资源、来自其他 C# 代码),这涉及进行一些处理,然后将数据发送到函数。

进行此调用的代码部分看起来像这样(简化);

// In Setup
client = new HttpClient();

// In the main action, after some processing
PostMessage(data).Wait();

// Defined seperately
private async Task PostMessage(string message) {
  var response = await client.PostAsync(functionUrl, message);
  response.EnsureSuccessStatusCode();
}

上面的 functionUrl 看起来像 https://namespace.azurewebsites.net/api/name?code=key(带有适当的替换)。

当这段代码运行时,我得到一个安全异常。该消息似乎没有帮助,但我在下面复制了它。我已经设法确认它肯定是被await client.PostAsync(functionUrl, message) 行抛出的。

我已经使用具有不同 url 的相同代码进行了测试 - 特别是 azureOathUrl (https://login.microsoftonline.com/common/oauth2/token),因为我在此 CRM 的另一个工作流中向它发出请求 - 并且没有引发安全异常。

如何向 azure 函数发出请求?我需要做一些具体的事情来连接到某些 url(我没有看到任何参考)?

引发安全异常;

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Security.SecurityException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #2E606488Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ActivityId>48ed9d3c-bd82-4e65-b65f-c3c75501137e</ActivityId>
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>System.Security.SecurityException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #2E606488</Message>
<Timestamp>2019-09-16T13:44:30.7417027Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource>PluginExecution</ExceptionSource>
<InnerFault i:nil="true" />
<OriginalException>System.Security.SecurityException
at System.ComponentModel.Win32Exception.GetObjectData(SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.ObjectCloneHelper.GetObjectData(Object serObj, String&amp; typeName, String&amp; assemName, String[]&amp; fieldNames, Object[]&amp; fieldValues)


at Microsoft.Crm.Sandbox.SandboxAppDomainHelper.Execute(IOrganizationServiceFactory organizationServiceFactory, String customActivityTypeName, IExecutionContext requestContext, Dictionary`2 sandboxServices, Boolean useDrawbridgeEnabled, Boolean chaosFailAppDomain)
at Microsoft.Crm.Sandbox.SandboxWorker.ExecuteCustomWorkflowActivity(SandboxCallInfo callInfo, SandboxCustomActivityExecutionContext requestContext, Guid pluginAssemblyId, Int32 sourceHash, String assemblyName, Guid pluginTypeId, String pluginTypeName, SandboxRequestCounter&amp; workerCounter, Boolean returnTraceInfo)</OriginalException>
<TraceText i:nil="true" />
</OrganizationServiceFault>

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Crm.Sandbox.ISandboxHost.ExecuteCustomWorkflowActivityAndReturnTraceInfo(SandboxCallInfo callInfo, SandboxCustomActivityExecutionContext requestContext, Guid pluginAssemblyId, Int32 sourceHash, String assemblyName, Guid pluginTypeId, String pluginTypeName, String assemblyContents, Boolean returnTraceInfo)
at Microsoft.Crm.Sandbox.SandboxCustomActivity.Execute(SandboxClient client, SandboxCallTracker callTracker, IExecutionContext requestContext, String assemblyContents, Boolean returnTraceInfo)
at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context)

【问题讨论】:

  • 快速问题,您能否从您的 CRM 用户访问 Internet Web,我的意思是 CRM 插件在服务帐户用户 IIS user 下运行,在我的情况下用户是 crmtestappserv 我有一个类似的问题我的 onPrem CRM 2016。问题是这个用户在尝试访问互联网时没有权限,因此失败了。插件和工作流程序集在 CRM 中在此用户下运行。
  • 我有另一个工作流向 login.microsoftonline.com 发出请求,该工作流有效(我也在这段代码中测试了该 url),所以我很确定它能够到达互联网。

标签: dynamics-crm


【解决方案1】:

我有一些想法可能会有所帮助。

首先,每次都要小心更新一个 HttpClient。如果您获得足够的流量,这可能会导致套接字耗尽。 (很难学到这一点。)

其次,您是否通过这样做将 TLS 设置为 1.2? System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

我发现如果你不指定 TLS1.2,很多调用都会失败,如果我没记错的话,Azure Functions 是需要 1.2 的。

第三,您的 Azure Function 是否有任何防火墙或安全措施?您可能会接到未经授权的电话。

【讨论】:

    猜你喜欢
    • 2016-04-25
    • 1970-01-01
    • 2015-07-22
    • 2016-09-05
    • 1970-01-01
    • 1970-01-01
    • 2013-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多