繁体   English   中英

从WCF服务(通过代理)从CRM获取数据会引发错误

[英]Getting data from CRM (by proxy) from WCF service throws error

情况:我正在研究Dynamics CRM 2016 Online。 我在实体的statechange上调用插件。 在此插件中,我调用了外部WCF服务(托管在Azure中)。 我为此使用的代码是:

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>");

为此,我使用该服务的web.config中的连接字符串。

现在,对于奇怪的部分:当我在现场生产环境中执行setstate动作时,一切工作正常。 但是,我收到了以下错误的机票:

<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>

我很困惑,因为我在CRM中使用的用户具有完全相同的权限和角色来执行此操作,但是,使用相同角色的客户会遇到此错误。 更令人烦恼的是:我无法重现此错误,因为一切都很好。 有人知道会发生什么吗?

看起来您的异常是在候选人的SetStateDynamicEntity的Plugin.Candidate.UpdateIndexOnStateChange插件中。 无论该插件在做什么,都需要它没有的数据库权限。

请求类型为'System.Data.SqlClient.SqlClientPermission,System.Data,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的权限失败。

如果插件以主叫用户身份运行,这将解释为什么它适用于某些人,而不适用于其他人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM