使用 QueryExpression 创建 OrganizationServiceFault

问题描述

我需要一些帮助。这是我使用的第一个 QueryExpression,因为我不得不将我的 SDK 更新到 365。

此时我什至没有做任何困难的事情,但是如果我在代码中使用 QueryExpression(就像我之前做过 100 次一样),我会得到一个 OrganizationServiceFault。

这是在 VisualStudio 2017 中构建的,使用 365SDK 插件注册工具创建插件

这里是基本代码在这一点上它是真正的基本代码

using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace TrainerAppHistory.TransferHistory
{

/// <summary>
/// PreOperationipmahr_trainerapplicationUpdate Plugin.
/// Fires when the following attributes are updated:
/// ipmahr_transferhistory
/// </summary>    
public class PreOperationipmahr_trainerapplicationUpdate : PluginBase
{

    public PreOperationipmahr_trainerapplicationUpdate(string unsecure,string secure)
        : base(typeof(PreOperationipmahr_trainerapplicationUpdate))
    {

        // Todo: Implement your custom configuration handling.
    }
    private readonly string preImageAlias = "PreImage";
    protected override void ExecuteCrmPlugin(LocalPluginContext localContext)
    {
        if (localContext == null)
        {
            throw new InvalidpluginExecutionException("localContext");
        }

        IPluginExecutionContext context = localContext.PluginExecutionContext;
        IOrganizationService server = localContext.OrganizationService;
        Entity Training = (Entity)context.InputParameters["Target"];
        Entity preImageEntity = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.preImageAlias)) ? context.PreEntityImages[this.preImageAlias] : null;
        EntityReference Contact = (EntityReference)preImageEntity.Attributes["ipmahr_contactid"];
        
        bool transfer = Training.GetAttributeValue<bool>("ipmahr_transferhistory");
        Guid recordID = Training.GetAttributeValue<Guid>("ipmahr_trainerapplicationid");
        Guid contactid = Contact.Id;
        

        if (transfer == true)
        {
            QueryExpression TopRecord = new QueryExpression("ipmahr_trainerapplication");
            TopRecord.ColumnSet = new ColumnSet("ipmahr_trainerapplicationid");
             EntityCollection results1 = server.RetrieveMultiple(TopRecord);

            if (results1.Entities.Count > 1)
            {
                Training.Attributes["new_comments"] = "found them all";
               
            }

            //End Code

        }
    }
}
}

当我删除 QueryExpression 并像这样对记录进行简单更新时 Training.Attributes["new_comments"] = "这行得通"; 然后我更新记录没有错误

我尝试在 QueryExpression 中填充一个变量,然后在 QE 之外更新(以测试)。但问题似乎只是量化宽松的存在。

我不知道接下来要看什么。我发现的任何东西似乎都没有帮助。我使用了注册插件工具来生成这个插件

插件跟踪显示以下内容,我认为这是关键。但我找到答案的运气并不好。

System.ServiceModel.CommunicationObjectFaultedException:通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为它处于故障状态。

解决方法

一直想回到这个问题。事实证明,这根本不是代码,而是分析器服务和/或沙箱服务。 (我不确定哪个托管公司没有回复我。但是在他们周末对服务器做了一些事情后,代码现在可以工作了。)但感谢您的回答。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...