0

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 (i.e. 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 (i.e. "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)

ChrisHDog
  • 4,473
  • 8
  • 51
  • 77

1 Answers1

0

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

MaPi
  • 1,601
  • 3
  • 31
  • 64
  • correct, it has no email field, but the interface i want to use does, so when i implement it i map it to the emailaddress1 ... however when i send the Account object i get the above error (which is unexpected as I'd assume it wouldn't read/send the email property, just the underlying emailaddress1) – ChrisHDog Jun 09 '14 at 13:14
  • if i do take off email (and the interface) it works, but i can't implement the interface without email (and i want to implement the interface) – ChrisHDog Jun 09 '14 at 13:15
  • Yes, but you are also adding an EMail field to the account that can't be present when you are saving. It's like having an Object with 4 fields and trying to save it inside a table with 3. – MaPi Jun 09 '14 at 13:26
  • you can have an object with 4 fields and save it inside a table with 3 if two of the fields are just different names on the same data (so there are 3 data points, with 4 accessors ... or 3 private variables with 4 public properties on those private variables) – ChrisHDog Jun 10 '14 at 06:48
  • I think we might be missing the point here. CRM does not allow you to save Entities that have fields that are not specified for that Entity. If you want to keep using your inheritance you'll have to make your Account class extend the MyNamespace.CustomerRelationshipManagement.MicrosoftDynamics.CrmServiceReference.Account and inherit from IMyAccount. Then change the Email property in IMyAccount to EMailAddress1 and in your class you'll have to mark EMailAddress1 with the new keyword – MaPi Jun 10 '14 at 09:16