2016-11-08 116 views
0

情況:我正在使用Dynamics CRM 2016 Online。我正在調用一個實體狀態變化的插件。在這個插件中,我調用了一個外部WCF服務(在Azure中託管)。我使用的代碼是:從WCF服務(通過代理服務器)獲取數據引發錯誤

private void AddToIndex(EntityReference canRef) 
     { 
      ChannelFactory<ServiceReference1.IIndexing> factory = GetFactory(); 
      var channel = factory.CreateChannel(); 
      channel.IndexOneCandidate(canRef.Id); 
      factory.Close(); 
     } 

     private ChannelFactory<ServiceReference1.IIndexing> GetFactory() 
     { 
      BasicHttpBinding myBinding = new BasicHttpBinding(); 
      myBinding.Name = "BasicHttpBinding_IndexingService"; 
      myBinding.Security.Mode = BasicHttpSecurityMode.None; 
      myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; 
      myBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None; 
      myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; 

      EndpointAddress endPointAddress = new EndpointAddress("http://<correcturl>/indexing.svc"); 
      ChannelFactory<ServiceReference1.IIndexing> factory = new ChannelFactory<ServiceReference1.IIndexing>(myBinding, endPointAddress); 
      return factory; 
     } 

我已經包含由svutil創建的Reference.cs文件。

在此服務中,我需要從CRM中獲取數據以使用它將數據提交到另一個(外部)服務。我這樣做是通過創建一個服務代理:

IOrganizationService service = new OrganizationService("<orgname>"); 

爲此,我使用的ConnectionString這是我服務的web.config文件。

現在的奇怪的部分:當我在現場製作環境中執行setstate動作時,一切正常。不過,我已經收到的票誰得到了以下錯誤:因爲我用一個用戶具有完全相同的權利CRM &角色來執行這個動作,但是,我的客戶端使用

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Body> 
     <s:Fault> 
      <faultcode>s:Client</faultcode> 
      <faultstring xml:lang="en-US">Unexpected exception from plug-in (Execute): Plugin.Candidate.UpdateIndexOnStateChange: System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.</faultstring> 
      <detail> 
       <OrganizationServiceFault xmlns="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
        <ErrorCode>-2147220956</ErrorCode> 
        <ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/> 
        <Message>Unexpected exception from plug-in (Execute): Plugin.Candidate.UpdateIndexOnStateChange: System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.</Message> 
        <Timestamp>2016-11-07T08:52:50.0726198Z</Timestamp> 
        <InnerFault i:nil="true"/> 
        <TraceText> 
    [Plugin.Candidate: Plugin.Candidate.UpdateIndexOnStateChange] 
    [2b70fb94-1d9c-e611-8107-5065f38a3b11: Plugin.Candidate.UpdateIndexOnStateChange: SetStateDynamicEntity of candidate] 

        </TraceText> 
       </OrganizationServiceFault> 
      </detail> 
     </s:Fault> 
    </s:Body> 
</s:Envelope> 

我puzzelled,這個相同的角色得到這個錯誤。更令人討厭的是:我無法重現這個錯誤,因爲在我的最後,一切正常。任何人都知道可能會發生什麼?

+0

所以你無法在生產中觸發這個錯誤,因爲你的自我,但其他人能夠? – Daryl

+0

確實。我無法在生產中複製,但我的客戶可以。唯一的區別是在CRM上登錄的用戶 - 但我們使用的測試帳戶與我的客戶使用的帳戶具有完全相同的角色... –

回答

0

看起來你的例外是在候選人的SetStateDynamicEntity的Plugin.Candidate.UpdateIndexOnStateChange插件中。不管那個插件做什麼,都需要它沒有的數據庫權限。

Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

如果插件作爲下主叫用戶運行,這可以解釋爲什麼它會爲一些人的工作,而不是別人。

+0

插件作爲調用用戶運行,但僅用於驗證if此用戶有權更改實體的狀態。在那之後,唯一的一件事就是解決一個WCF服務,它將被更改的實體的ID傳遞給它,就這些了。 插件和服務都不需要CRM以外的任何數據庫訪問。該服務確實從CRM獲取數據,但通過代理執行此操作(並且此服務的web.config使用sysadmin帳戶,因此沒有安全問題)。 –

相關問題