2011-09-20 37 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。 –