2010-10-28 7 views
0

J'ai un DomainService avec quelques méthodes.La méthode RIA n'apparaît pas dans Silverlight

On a un type de retour de chaîne et aucun paramètre:

public string MyMethod1() { } 

je peux appeler celui de Silverlight.

On a un type de vide de retour, et un paramètre qui est un objet de domaine (j'utilise LinqToSqlDomainService et cet objet fait partie du DataContext):

public void MyMethod2(MyDomainObject object) { } 

Je peux aussi appeler celui-ci de Silverlight .

Un autre a un type de chaîne de retour et un paramètre qui est un objet de domaine:

public string MyMethod3(MyDomainObject object) { } 

Je ne peux pas appeler celui de Silverlight, la méthode ne soit pas généré sur le proxy. Pourquoi n'est-il pas généré et que puis-je faire à ce sujet?

Répondre

2

Essayez d'ajouter l'attribut [Invoke] à l'opération.

J'ai créé un exemple d'application défini avec le contrat suivant et j'ai réussi à obtenir les trois méthodes générées dans l'application Silverlight.

Voici le fichier DBML. LINQ to SQL DBML file

Voici le service défini.

[EnableClientAccess()] 
public class DomainService1 : LinqToSqlDomainService<DataClasses1DataContext> 
{ 
    public Player GetPlayer() 
    { 
     throw new NotImplementedException(); 
    } 

    public void MyMethod(Player player) 
    { 
    } 

    [Invoke] 
    public string MyMethod2(Player player) 
    { 
     return String.Empty; 
    } 
} 

Et ce fut le code généré dans le projet Silverlight:

/// <summary> 
/// Gets an EntityQuery instance that can be used to load <see cref="Player"/> entities using the 'GetPlayer' query. 
/// </summary> 
/// <returns>An EntityQuery that can be loaded to retrieve <see cref="Player"/> entities.</returns> 
public EntityQuery<Player> GetPlayerQuery() 
{ 
    this.ValidateMethod("GetPlayerQuery", null); 
    return base.CreateQuery<Player>("GetPlayer", null, false, false); 
} 

/// <summary> 
/// Invokes the 'MyMethod' method of the specified <see cref="Player"/> entity. 
/// </summary> 
/// <param name="player">The <see cref="Player"/> entity instance.</param> 
public void MyMethod(Player player) 
{ 
    player.MyMethod(); 
} 

/// <summary> 
/// Asynchronously invokes the 'MyMethod2' method of the domain service. 
/// </summary> 
/// <param name="player">The value for the 'player' parameter of this action.</param> 
/// <param name="callback">Callback to invoke when the operation completes.</param> 
/// <param name="userState">Value to pass to the callback. It can be <c>null</c>.</param> 
/// <returns>An operation instance that can be used to manage the asynchronous request.</returns> 
public InvokeOperation<string> MyMethod2(Player player, Action<InvokeOperation<string>> callback, object userState) 
{ 
    Dictionary<string, object> parameters = new Dictionary<string, object>(); 
    parameters.Add("player", player); 
    this.ValidateMethod("MyMethod2", parameters); 
    return ((InvokeOperation<string>)(this.InvokeOperation("MyMethod2", typeof(string), parameters, true, callback, userState))); 
} 

/// <summary> 
/// Asynchronously invokes the 'MyMethod2' method of the domain service. 
/// </summary> 
/// <param name="player">The value for the 'player' parameter of this action.</param> 
/// <returns>An operation instance that can be used to manage the asynchronous request.</returns> 
public InvokeOperation<string> MyMethod2(Player player) 
{ 
    Dictionary<string, object> parameters = new Dictionary<string, object>(); 
    parameters.Add("player", player); 
    this.ValidateMethod("MyMethod2", parameters); 
    return ((InvokeOperation<string>)(this.InvokeOperation("MyMethod2", typeof(string), parameters, true, null, null))); 
} 
+0

« opération nommée « Method4 » ne sont pas conformes à la signature requise types de paramètres doivent être un type d'entité ou l'un des prédéfini. types sérialisables. " - Mon type est défini dans mon fichier de classes LinqToSql (.dbml). Il n'a pas d'attribut Entity, juste un TableAttribute. –

+0

Votre type a-t-il une clé définie? –

+0

La colonne ID est définie comme clé primaire dans la base de données et dans le concepteur LinqToSql. Dans le code généré, la propriété ID est marquée avec '[ColumnAttribute (IsPrimaryKey = true)]'. –

Questions connexes