2011-09-20 35 views
2

我们有一个安装程序(vdproj msi),它使用OrganizationServiceProxy安装Dynamics 2011托管包(作为嵌入式资源存储的zip文件)。它构建OrganizationServiceProxy如下:Dynamics 2011 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); 

这产生了奇妙的令人费解的错误:

The Web Service plug-in failed in OrganizationId: 510c06a3-6ee9-43a7-ba54-677054348813; SdkMessageProcessingStepId: 1b830950-e106-4ee1-b3fd-d348cb65dc8d; EntityName: none; Stage: 30; MessageName: ImportSolution; AssemblyName: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: Microsoft.Crm.Extensibility.InternalOperationPlugin; Exception: Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values) at Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider serviceProvider) at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context) at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context) Inner Exception: System.Globalization.CultureNotFoundException: Culture is not supported. Parameter name: culture 0 (0x0000) is an invalid culture identifier. at System.Globalization.CultureInfo.InitializeFromCultureId(Int32 culture, Boolean useUserOverride) at Microsoft.Crm.Tools.ImportExportPublish.SolutionPackageUpgrade..ctor(ExecutionContext context) at Microsoft.Crm.Tools.ImportExportPublish.RootImportHandler..ctor(ImportXml parent, Boolean overwriteUnmanagedCustomizations, Boolean publishWorkflows, Byte[] compressedCustomizationFile, Boolean setup, Version existingDatabaseVersion, ExecutionContext context, Boolean extractAllFiles) at Microsoft.Crm.Tools.ImportExportPublish.ImportXml..ctor(Boolean overwriteUnmanagedCustomizations, Boolean publishWorkflows, Byte[] compressedCustomizationFile, Guid importJobId, Boolean convertToManaged, ExecutionContext context) at Microsoft.Crm.WebServices.ImportXmlService.ImportSolution(Boolean overwriteUnmanagedCustomizations, Boolean publishWorkflows, Byte[] customizationFile, Guid importJobId, Boolean convertToManaged, ExecutionContext context)

几个小时的研究和拆卸的Microsoft Dynamics内部的dll后(如果它不那么难过,我需要这样做会很有趣),我发现传入请求的ExecutionContext中的CallerId w为空(即使请求使用提供的凭证正确认证)。

所以,我抬头一看SystemUserId我想从SystemUser表中使用和指定

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

你瞧,在ImportSolutionRequest这样做得手后。

我留下的问题:

  1. 有没有完成,而无需指定来电显示的实际工作这个荒谬的基本任务的另一种方式?为什么没有它,它不工作?
  2. 如果不是,我如何根据我提供的凭据(无需对其进行硬编码)获取callerId以设置OrganizationServiceProxy。
  3. 为什么我会在全新的服务器上全新安装Dynamics的完全默认安装时遇到这些问题?

回答

1

我没有太多的编程导入解决方案的经验,所以我不能回答1.对于问题2,我认为你可以使用WhoAmIRequest。至于3,我不确定我会将它归类为一个问题,直到我得到1的答案。:)

+0

WhoAmIRequest为隐藏用户返回一个UserId,显然第一次自动创建导入请求...不是我认证的用户。似乎有两个自动创建的用户:SYSTEM,SYSTEM和INTEGRATION,INTEGRATION ...以及进一步如果我设置client.CallerId = whoAmIResponse.UserId,我得到上述关于文化不被支持的错误。这些隐藏的用户不会在用户界面中显示。 – Jeff

+0

至于它以编程方式运行...以及微软自己的例子如何做到这一点不编译,所以我会很惊讶,如果他们甚至知道他们的API如何工作或自alpha发布以来已经测试... – Jeff

+0

IIRC,在CRM 4.0中,我们会对“服务帐户”用户(仅针对计划任务或门户网站代码创建的用户)产生奇怪的问题。如果我们没有至少一次作为服务帐户登录到CRM Web UI,则用户的UserSettings记录永远不会在数据库中正确设置。这会导致像上面这样的奇怪错误(基本上是一种“空”文化)。问题是为什么WhoAmI返回这个“系统”用户而不是用户运行安装程序包?也许“系统”用户也有空的UserSettings。 –