7

Howdy, ya'll! First question on StackOverflow! :-)

So here's the scenario: We're working on a web app with Silverlight 4 and using WCF RIA Services 1.0 SP1 Beta for the web service. I have my entities in the Entity Framework Designer, but I'm using a slightly-modified ADO.NET C# POCO Entity Generator template to generate the classes.

What I'd like to do is have a method inside a Domain Service with the following signature:

[EnableClientAccess]
public class ResultService : DomainService
{
    [Invoke]
    public SerializableResult CalculateResult(EntityOne e1, EntityTwo e2);
}

I am returning both EntityOne and EntityTwo to the client through queries in other services, like so:

[EnableClientAccess]
public class EntityOneService : DomainService
{
    public IQueryable<EntityOne> GetEntityOnes();
}

[EnableClientAccess]
public class EntityOneService : DomainService
{
    public IQueryable<EntityTwo> GetEntityTwos();
}

Those classes are successfully being generated in the Silverlight project. The SerializableResult does not have a key.

When I try to compile, I get the following error: "Operation named 'CalculateResult' does not conform to the required signature. Parameter types must be an entity or complex type, a collection of complex types, or one of the predefined serializable types."

In my research, the most helpful information I found were in the comments of this post by Jeff Handley.

Of note, Peter asked in a comment:

I get an 'does not conform to the required signature ...' compile error if my complex object has an [Key] Attribute. When I remove this attribute I can use the object as parameter for an Invoke operation.

Jeff's response:

This is by design. Complex objects cannot have Key properties. If you have a Key the class gets treated as an Entity.

So it sounds as if any further efforts to try to get my method to work will be futile. However, I was wondering if anyone else has come across this problem, and what they did to solve it.

Thanks very much!

Adam W. McKinley
  • 765
  • 8
  • 13
  • Is SerializableResult getting generated on the client? I wonder if this is a bug in our Complex Type identification where we might be requiring the SerializableResult type to be surfaced as a property on an Entity before it can be used as an Invoke result. – Jeff Handley Nov 23 '10 at 15:50
  • If I try: "[Invoke] public SerializableResult CalculateResult();", SerializableResult _is_ generated on the client. – Adam W. McKinley Nov 23 '10 at 16:28
  • Then it sounds like something with your entities' shapes. Are EntityOne and EntityTwo generated as deriving from Entity? – Jeff Handley Nov 23 '10 at 16:42
  • They are being _generated_ as deriving from Entity in the client project, but they aren't deriving from Entity in the Service project. – Adam W. McKinley Nov 23 '10 at 17:38

2 Answers2

8

I have the following and it works for me.

namespace BusinessApplication2.Web
{
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;

    [EnableClientAccess()]
    public class DomainService1 : DomainService
    {
        public IQueryable<EntityOne> GetEntityOnes()
        {
            return null;
        }

        public IQueryable<EntityTwo> GetEntityTwos()
        {
            return null;
        }

        [Invoke]
        public SerializableResult GetSerializableResult(EntityOne one, EntityTwo two)
        {
            return new SerializableResult() { Result = "It woooooorrrked!" };
        }
    }

    public class EntityOne
    {
        [Key]
        public int Id { get; set; }
    }

    public class EntityTwo
    {
        [Key]
        public int Id { get; set; }
    }

    public class SerializableResult
    {
        public string Result { get; set; }
    }
}
moinudin
  • 134,091
  • 45
  • 190
  • 216
Jeff Handley
  • 4,134
  • 2
  • 23
  • 23
  • So I added two dummy Query methods in the DomainService (returning IQueryable and IQueryable) _alongside_ the CalculateResult method, and it compiled now! Why wouldn't it compile the original way? – Adam W. McKinley Nov 23 '10 at 17:31
  • This might be a bug in our "Shared Entities" feature that allows you to work with entity types across domain services. I will file it and let you know if it was by design or in fact a bug. – Jeff Handley Nov 23 '10 at 17:50
  • As Adam noted, this is in fact by design and not a bug. – Jeff Handley Nov 24 '10 at 17:05
  • Thanks!!! Earlier I had only one set method which didn't complied (Failed with message "Operation named 'XXX' does not conform to the required signature. Parameter types must be an entity type or one of the predefined serializable types") By adding one dummy Query method as per Jeff Handley's example, I was able to compile my code successfully. – Vaibhav Gawali Mar 13 '11 at 21:02
6

Many thanks to Mr. Jeff Handley and Mr. Dinesh Kulkarni for the answer (through Twitter).

In order for an Entity to be used as a parameter in an invoke method, that Entity must be exposed through a query method existing within the same DomainService. The intention for this restriction is that

"Each domain service needs to be able to stand on its own."

By adding two dummy Query methods (see Jeff's answer for an example), I was able to compile my code.

Adam W. McKinley
  • 765
  • 8
  • 13