2016-11-08 112 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帐户,因此没有安全问题)。 –

相关问题