简体   繁体   中英

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

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)

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.

This is unexpected as I'm sending a Microsoft.Crm.Sdk.Data.Services.Account object so it shouldn't have Email on it? 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?

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)

The Account entity has no Email field. It has an emailaddress1 one though, try with that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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