views:

791

answers:

3

I have a WCF RIA Domain Service that contains a method I'd like to invoke when the user clicks a button:

[Invoke]
public MyEntity PerformAnalysis(int someId)
{
    return new MyEntity();
}

However, when I try to compile I'm given the following error:

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

The thing is, as far as I can tell, MyEntity is an entity:

[Serializable]
public class MyEntity: EntityObject, IMyEntity
{
    [Key]
    [DataMember]
    [Editable(false)]
    public int DummyKey { get; set; }

    [DataMember]
    [Editable(false)]
    public IEnumerable<SomeOtherEntity> Children { get; set; }
}

I figure I'm missing something simple here. Could someone please tell me how I can create an invokable method that returns a single MyEntity object?

A: 

Did you get an answer to this...I have the EXACT same scenario!???

Nabeal
I've answered above. By the way, your question should have been added as a comment, not a question.
Duncan Bayne
A: 

This question was answered by YasserMohamedMCTS over on the Silverlight Forum.

Duncan Bayne
A: 

Create Your own class in server side project like:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;
using System.Data.Objects.DataClasses;

namespace yournamespace
{
    [DataContract]    
    public class Custom : EntityObject
    {

    [DataMember()]
    [Key()]
    public int id { set; get; }

    [DataMember()]
    public string name { set; get; }

    public Custom()
    {
        name = "Pouya";
    }
}
}

add your method to your DomainService in server side project like:

    public Custom GetCustom()
    {
        return new Custom();
    }

add these code to one of your page at client side project

public partial class Admin : Page
    {
        LoadOperation<Custom> operation;
        Custom ali = new Custom();
    public Admin()
    {
        InitializeComponent();
    }

    // Executes when the user navigates to this page.
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        operation = DomainContext.Load(DomainContext.GetCustomQuery());            
        operation.Completed += new EventHandler(operation_Completed);
    }

    void operation_Completed(object sender, EventArgs e)
    {
        if (!operation.HasError)
        {
            ali = operation.Entities.FirstOrDefault();
        }             
    }

}

Enjoy it

Pouya Shayan Arani Vancouver,Bc. Canada

Pouya Shayan Arani

related questions