【问题标题】:Dynamics 2011 OrganizationServiceProxy AuthenticationDynamics 2011 组织服务代理身份验证
【发布时间】:2011-11-21 11:44:22
【问题描述】:

我们有一个安装程序 (vdproj msi),它使用 OrganizationServiceProxy 安装 Dynamics 2011 受管软件包(存储为嵌入式资源的 zip 文件)。它按如下方式构造了 OrganizationServiceProxy:

var organizationUri = new Uri(string.Format(
  ORGANIZATION_SERVICE_URI_TEMPLATE, configuration.WebServiceUrl, 
  configuration.CrmOrganizationName));

var credentials = new ClientCredentials();
credentials.Windows.ClientCredential = GetNetworkCredentials();

credentials.UserName.UserName = credentials.Windows.ClientCredential.UserName;
credentials.UserName.Password = credentials.Windows.ClientCredential.Password;

var client = new OrganizationServiceProxy(organizationUri, null, credentials, null)
  { Timeout = TimeSpan.FromMilliseconds(WEB_SERVICE_TIMEOUT) };

return client;

并执行 ImportSolutionRequest

var importSolutionRequest = new ImportSolutionRequest
{
  CustomizationFile = Resources.DynamicsSolution,
  ImportJobId = Guid.NewGuid()
};
service.Execute(importSolutionRequest);

这会产生非常模糊的错误:

Web Service 插件在 OrganizationId 中失败:510c06a3-6ee9-43a7-ba54-677054348813; SdkMessageProcessingStepId:1b830950-e106-4ee1-b3fd-d348cb65dc8d;实体名称:无;阶段:30;消息名称:ImportSolution;程序集名称:Microsoft.Crm.Extensibility.InternalOperationPlugin,Microsoft.Crm.ObjectModel,版本=5.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35;类名:Microsoft.Crm.Extensibility.InternalOperationPlugin;异常:未处理的异常:System.Reflection.TargetInvocationException:调用的目标已引发异常。 在 System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo 方法,对象目标,Object[] 参数,SignatureStruct& sig,MethodAttributes methodAttributes,RuntimeType typeOwner) 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object[] 参数,CultureInfo 文化,布尔型 skipVisibilityChecks) 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object[] 参数,CultureInfo 文化) 在 System.Web.Services.Protocols.LogicalMethodInfo.Invoke(对象目标,对象 [] 值) 在 Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider 服务提供者) 在 Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext 上下文) 在 Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext 上下文) 内部异常:System.Globalization.CultureNotFoundException:不支持文化。 参数名称:文化 0 (0x0000) 是无效的区域性标识符。 在 System.Globalization.CultureInfo.InitializeFromCultureId(Int32 文化,布尔值 useUserOverride) 在 Microsoft.Crm.Tools.ImportExportPublish.SolutionPackageUpgrade..ctor(ExecutionContext 上下文) 在 Microsoft.Crm.Tools.ImportExportPublish.RootImportHandler..ctor(ImportXml 父级,布尔覆盖 UnmanagedCustomizations,布尔 publishWorkflows,字节 [] 压缩自定义文件,布尔设置,现有数据库版本,ExecutionContext 上下文,布尔提取所有文件) 在 Microsoft.Crm.Tools.ImportExportPublish.ImportXml..ctor(布尔覆盖UnmanagedCustomizations,布尔publishWorkflows,字节[]压缩自定义文件,Guid importJobId,布尔convertToManaged,ExecutionContext上下文) 在 Microsoft.Crm.WebServices.ImportXmlService.ImportSolution(Boolean overwriteUnmanagedCustomizations, Boolean publishWorkflows, Byte[] customizeFile, Guid importJobId, Boolean convertToManaged, ExecutionContext context)

经过几个小时的研究和反汇编 Microsoft Dynamics 内部 dll(如果我需要这样做不是很伤心的话会很有趣),我发现传入请求的 ExecutionContext 中的 CallerId 是空的(即使请求使用提供的凭据正确验证)。

所以,我从 SystemUser 表中查找了我想使用的 SystemUserId 并指定了

client.CallerId = Guid.Parse("94DB2FFC-DBDE-E011-95D5-005056AF0052");

你瞧,ImportSolutionRequest 在执行此操作后成功了。

剩下的问题是:

  1. 是否有另一种方法可以在不指定实际有效的 CallerId 的情况下完成这个荒谬的基本任务?为什么没有它就不能工作?
  2. 如果没有,我如何根据我提供的凭据在 OrganizationServiceProxy 上设置 callerId(无需硬编码)。
  3. 为什么我在全新服务器上全新、完全默认安装 Dynamics 时会出现这些问题?

【问题讨论】:

    标签: .net dynamics-crm dynamics-crm-2011


    【解决方案1】:

    我没有太多以编程方式导入解决方案的经验,因此无法回答 1。对于问题 2,我认为您可以使用 WhoAmIRequest。至于 3,在我得到 1 的答案之前,我不确定是否会将其归类为问题。:)

    【讨论】:

    • WhoAmIRequest 返回一个隐藏用户的 UserId,该用户显然是在我第一次发出导入请求时自动创建的……而不是我正在验证的用户。似乎有两个自动创建的用户:SYSTEM、SYSTEM 和 INTEGRATION、INTEGRATION ...如果我设置 client.CallerId = whoAmIResponse.UserId,我会收到上述关于不支持文化的错误。这些隐藏的用户不会显示在 UI 的任何地方。
    • 至于以编程方式运行它......好吧,微软自己的如何做到这一点的例子没有编译,所以如果他们知道他们的 API 是如何工作的或者从 alpha 开始测试它,我会感到惊讶释放...
    • IIRC,在 CRM 4.0 中,我们会遇到“服务帐户”用户(仅为计划任务或 Web 门户代码创建的用户)的奇怪问题。如果我们没有以服务帐户身份至少登录一次 CRM Web UI,则用户的 UserSettings 记录将永远无法在数据库中正确设置。这会导致像上面这样的奇怪错误(基本上是“空”文化)。问题是为什么 WhoAmI 返回这个“系统”用户而不是运行你的安装包的用户?也许“系统”用户也有 null UserSettings。
    • 我验证了 usersettingsbase 表没有系统/集成帐户的条目(这是 uiculture 所在的位置)......所以有什么想法可以让 Dynamics 使用正确的帐户吗?
    • 不是我的头,但我会专注于您的凭据代码。我相信前端 Web 服务器的 NETWORK SERVICE 帐户以 SYSTEM 身份登录,因为如果您不为 Async 服务指定服务帐户,它会使用 NETWORK SERVICE 并且工作流记录显示为由 SYSTEM 创建。那么这个安装包是由用户直接运行,还是某个服务或其他运行它的东西以网络服务登录?
    猜你喜欢
    • 2011-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 1970-01-01
    • 2020-03-13
    相关资源
    最近更新 更多