简体   繁体   English

使用Microsoft.Xrm.Tooling创建服务和上下文

[英]Using Microsoft.Xrm.Tooling to create a service and context

I am now updating an integration program written for Dynamics 2015 in order to support Dynamics 365. At the moment it uses the Microsoft.Xrm.Client dll methods to create an organization service context. 我现在正在更新为Dynamics 2015编写的集成程序,以支持Dynamics365。目前,它使用Microsoft.Xrm.Client dll方法创建组织服务上下文。 Is there an equivalent to Microsoft.Xrm.Tooling as Microsoft.Xrm.Client seems unsupported. 是否存在与Microsoft.Xrm.Tooling等效的功能,因为似乎不支持Microsoft.Xrm.Client。

 var getCRMOrgService = CreateCRMOrgService(logger);
            var client = CreatePosPerfectConnection(logger);

            if (getCRMOrgService != null)
            {
                using (var ctx = new DataContext(new CrmOrganizationServiceContext(getCRMOrgService)))
                {
                    ctx.TryAccessCache(cache => cache.Mode = OrganizationServiceCacheMode.Disabled);
/******Rest of the code******/

Here I require to change the CreateCRMOrgService and CrmOrganizationServiceContext Methods to the ones supported by Microsoft.Xrm.Tooling alone 在这里,我需要将CreateCRMOrgService和CrmOrganizationServiceContext方法更改为单独由Microsoft.Xrm.Tooling支持的方法。

It looks like you'll want to switch to CrmServiceClient , which is in the Microsoft.Xrm.Tooling.Connector namespace. 看来您想切换到CrmServiceClient ,它位于Microsoft.Xrm.Tooling.Connector命名空间中。

To get the NuGet package: In your project, right click on the References node and select Manage NuGet Packages. 获取NuGet软件包:在您的项目中,右键单击“引用”节点,然后选择“管理NuGet软件包”。 Under Browse search for "xrm tooling". 在浏览下搜索“ xrm工具”。 Install Microsoft.CrmSdk.XrmTooling.CoreAssembly and you should be good to go. 安装Microsoft.CrmSdk.XrmTooling.CoreAssembly,您应该一切顺利。

Then create a CrmServiceClient via a connection string 然后通过连接字符串创建一个CrmServiceClient

var svc = new CrmServiceClient(connectionString);

Then for the context (query provider) do something like this (please note this is untested code): 然后针对上下文(查询提供程序)执行以下操作(请注意,这是未经测试的代码):

private List<Entity> getRecords()
{
    using (var context = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(svc))
    {
        var result = from e in organizationServiceContext.CreateQuery("new_entity")
                     where e.GetAttributeValue<string>("new_field") == "my value"
                     select e;
        return result.Take(100).ToList();
    }
}

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

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