简体   繁体   English

如何为MS-CRM 2013的MS代理类添加接口

[英]How do I add an Interface to a MS Proxy Class for MS-CRM 2013

So I have a MS Dynamics CRM 2013 installation that I'm trying to integrate some items to and want to send some data. 因此,我有一个MS Dynamics CRM 2013安装,试图将某些项目集成到其中并希望发送一些数据。 I have an interface (IAccnt) that I want to apply to the proxy class generated when I added the service refrence to ...XRMServices/2011/OrganizationData.svc/ (I added on a partial class) 我有一个接口(IAccnt),我想将此接口应用于将服务引用添加到... XRMServices / 2011 / OrganizationData.svc /时生成的代理类(在部分类上添加)

When I initially added the interface (it only had "Name" and "AccountNumber") everything was going along well (ie able to save items) ... I added a new item to the interface that didn't have a direct corollary ("Email") but that did map (so the getter and setter just passed data to and from this.EMailAddress1) 当我最初添加界面(它只有“ Name”和“ AccountNumber”)时,一切进展顺利(即能够保存项目)……我向界面添加了一个没有直接推论的新项目( “ Email”),但确实映射了(因此,getter和setter只是与this.EMailAddress1之间传递了数据)

With that change I now get the following error on save: Error processing request stream. 通过该更改,我现在在保存时收到以下错误:错误处理请求流。 The property name 'Email' specified for type 'Microsoft.Crm.Sdk.Data.Services.Account' is not valid. 为类型“ Microsoft.Crm.Sdk.Data.Services.Account”指定的属性名称“ Email”无效。

This is unexpected as I'm sending a Microsoft.Crm.Sdk.Data.Services.Account object so it shouldn't have Email on it? 这是意外的,因为我正在发送Microsoft.Crm.Sdk.Data.Services.Account对象,因此该对象上不应包含电子邮件? And regardless I should be able to send more information than needed? 并且无论我是否应该能够发送比所需更多的信息? Is there something I need to do to be able to add an Interface to a proxy class and have the save still work? 我需要做些什么才能将接口添加到代理类,并使保存仍然有效?

I've tried adding [XmlIgnore] and [IgnoreDataMember] on the public property implementation of Email, but same result ... Something like that (ie "ignore these properties when ".AddToAccountSet"/".SaveChanges()" would probably solve this isssue? 我已经尝试在Email的公共属性实现上添加[XmlIgnore]和[IgnoreDataMember],但结果却是相同的……(例如,“当“ .AddToAccountSet” /“。SaveChanges()”时忽略这些属性可能会解决)这个问题?

Interface Code 接口代码

public interface IMyAccount
{
   string Name { get; set; }
   string Email { get; set; }
}

Partial Class (partial on the proxy class created from service reference) 部分类(部分从服务参考创建的代理类)

namespace MyNamespace.CustomerRelationshipManagement.MicrosoftDynamics.CrmServiceReference
{
    public partial class Account : MyNamespace.Interfaces.IMyAccount
    {
        public string Email { get { return this.EMailAddress1; } set { this.EMailAddress1 = value; } }
    }
}

Where the error is raised from (attempt to add account) 引发错误的位置(尝试添加帐户)

var crmUri = new Uri("http://crminstallation/XRMServices/2011/OrganizationData.svc/");
var crmService = new CrmServiceReference.CrmInstallationContext(crmUri);
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;

var crmMyAccount = new CrmServiceReference.Account();
crmMyAccount.Name = "Test Account";
crmMyAccount.Email = "myemail@mydomain.com";

crmService.AddToAccountSet(crmMyAccount);
crmService.SaveChanges();

If Email is removed from the interface and from the partial class then it works (in that it saves a new account to CRM) 如果从界面和部分类中删除了电子邮件,那么它将起作用(因为它将新帐户保存到CRM)

The Account entity has no Email field. 帐户实体没有电子邮件字段。 It has an emailaddress1 one though, try with that 它有一个emailaddress1,尝试

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

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