开发者

RIA service needs dummy public, non-attributed methods to compile

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜