c# - 我已经使用 CrmSvcUtil 为 Dynamics CRM 2011 生成了早期绑定(bind)实体类 - 现在怎么办?

标签 c# sdk dynamics-crm dynamics-crm-2011

我已经设置了一个测试 Dynamics CRM 2011 服务器。

我已使用 SDK 的 CrmSvcUtil 实用程序生成早期绑定(bind)实体类(例如 mycrm.cs)。

我在 Visual Studio 中创建了一个新项目并添加了对 Microsoft.CRM.SDK.Proxy、Microsoft.Xrm.Sdk 和 System.Runtime.Serialization 的引用。

我还将 mycrm.cs 文件作为现有文件添加到我的项目中。

现在呢?

我知道,我知道...阅读 SDK。我试过:

Using the Early Bound Entity Classes in Code

Using the Early Bound Entity Classes for Create, Update, Delete

Create Early Bound Entity Classes with the Code Generation Tool (CrmSvcUtil.exe)

如果一定要叫我白痴 - 我敢肯定这些文章可能包含这些信息。我需要,但我没有看到它。帮助!

最佳答案

首先,您需要连接到 CRM 网络服务:

OrganizationServiceProxy orgserv;
ClientCredentials clientCreds = new ClientCredentials();
ClientCredentials devCreds = new ClientCredentials();


clientCreds.Windows.ClientCredential.UserName = "user";
clientCreds.Windows.ClientCredential.Password = "P@$$w0rd";
clientCreds.Windows.ClientCredential.Domain = "myDomain";
IServiceConfiguration<IOrganizationService> orgConfigInfo =
            ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(new Uri("https://myCRMServer/myOrg/XRMServices/2011/Organization.svc"));

orgserv = new OrganizationServiceProxy(orgConfigInfo, clientCreds);
orgserv.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

之后,您将使用您的 XrmServiceContext,或者您在这里的命名方式:

CrmSvcUtil.exe /url:http://servername/organizationname/XRMServices/2011/Organization.svc /out:.cs /username: /password: /domain: /namespace: /serviceContextName:XrmServiceContext

然后您可以从 link you posted 中的 CRUD 示例开始:)

更新联系人的例子:

using(var context = new XrmServiceContext(orgserv))
{
    Contact con = context.contactSet.FirstOrDefault(c => c.Name == "Test Contact");
    if(con != null)
    {
        con.City = "NY";

        context.UpdateObject(con);
        context.SaveChanges();
    }
}

希望对您有所帮助:)

关于c# - 我已经使用 CrmSvcUtil 为 Dynamics CRM 2011 生成了早期绑定(bind)实体类 - 现在怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12940895/

相关文章:

c# - 在 Jetbrains Rider 上构建时 Blazor App CS0103 错误,而在使用 VisualStudio 时没有错误

c# - 获取 Windows 注册表编辑器版本

xamarin - 在 Xamarin 中找不到 Android SDK

ios - Facebook sdk 4 iOS 用户信息电子邮件读取权限不起作用

ssl - C# "The request was aborted: Could not create SSL/TLS secure channel."- 偶尔发生

c# - 如何解析出 MS Word 格式?

c# - 使用JSON(UWP,C#)获取YouTube统计信息

maven - 在 Microsoft Windows 8.1 中运行 Apache Hadoop 2.7.0

c# - Dynamics 365 - 使用 IOrganizationService 创建 OrganizationServiceProxy

dynamics-crm - 插件调试 - 用户总是需要登录?