views:

54

answers:

2

I am implementing a Silverlight application with a WCF RIA service in the server side and I am experiencing a very strange behavior.

At this point the service is very simple and only has a few methods, all of them marked with the [Invoke] attribute. These methods are something like this:

[Invoke]
MyEntity DoWorkAndReturnEntity(string someParameter)
{
    var entity = new MyEntity();
    //Do some preocessing...
    return entity;
}

where the MyEntity type has one public property with the [Key] attribute:

public class MyEntity
{
    [Key]
    public int Key {get;set;}
}

Well, if I try to compile the solution, I get the following error:

Operation named 'DoWorkAndReturnEntity' does not conform to the required signature. Return types must be an entity, collection of entities, or one of the predefined serializable types.

And now comes the funny part. If I add a public dummy method that returns an entity of the same type, but has no Invoke attribute, then it compiles and works perfectly!

public MyEntity __Dummy()
{
    return null;
}

This happens with all methods, regardless of the type of the object returned. So I have to add a dummy method for each returned object type.

I am completely puzzled. What is happening here?

A: 

WCF RIA Services uses configuration-by-convention, your DoWorkAndReturnEntity method needs to be decorated with the [Query] attribute or with no attribute at all since [Query] is the default just like in your __Dummy method.

Rafa Castaneda
+1  A: 

The entity types are defined by the set of query methods in a domain service.

An invoke method cannot return an entity type unless it is one of the entities that are returned by the domain service... hence the __Dummy query method makes things work.

NikhilK