Question

I have a WCF service that generates loads Entity Framework objects (as well as some other structs and simple classes used to lighten the load) and sends them over to a client application.

I have changed 2 of the classes to implement an interface so that I can reference them in my application as a single object type. Much like this example: Is it Possible to Force Properties Generated by Entity Framework to implement Interfaces?

However, the interface type is not added to my WCF service proxy client thingymebob as it is not directly referenced in the objects that are being sent back over the wire.

Therefore in my application that uses the service proxy classes, I can't cast or reference my interface..

Any ideas what I'm missing?

Here's some example code:

//ASSEMBLY/PROJECT 1 -- EF data model

namespace Model
{
    public interface ISecurable
    {
        [DataMember]
        long AccessMask { get; set; }
    }

    //partial class extending EF generated class
    //there is also a class defined as "public partial class Company : ISecurable"
    public partial class Chart : ISecurable
    {
        private long _AccessMask = 0;
        public long AccessMask
        {
            get { return _AccessMask; }
            set { _AccessMask = value; }
        }

        public void GetPermission(Guid userId)
        {
            ChartEntityModel model = new ChartEntityModel();
            Task task = model.Task_GetMaskForObject(_ChartId, userId).FirstOrDefault();
            _AccessMask = (task == null) ? 0 : task.AccessMask;
        }
    }
}

//ASSEMBLY/PROJECT 2 -- WCF web service
namespace ChartService
{
    public Chart GetChart(Guid chartId, Guid userId)
    {
         Chart chart = LoadChartWithEF(chartId);
         chart.GetPermission(userId); //load chart perms
         return chart; //send it over the wire
    }
}
Was it helpful?

Solution

Interfaces won't come across as separate entities in your WSDL - they will simply have their methods and properties added to the object that exposes them.

What you want to accomplish you can do using abstract classes. These will come across as distinct entities.

Good luck. Let us know how you decided to proceed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top