开发者

RIA method does not appear in Silverlight

开发者 https://www.devze.com 2023-01-22 21:42 出处:网络
I have a DomainService with a few methods. One has a return type of string and no parameter: public st开发者_如何学运维ring MyMethod1() { }

I have a DomainService with a few methods.

One has a return type of string and no parameter:

public st开发者_如何学运维ring MyMethod1() { }

I can call this one from Silverlight.

One has a return type of void, and a parameter that is a domain object (I am using LinqToSqlDomainService and this object is part of the DataContext):

public void MyMethod2(MyDomainObject object) { }

I can also call this one from Silverlight.

Another one has a return type of string and a parameter that is a domain object:

public string MyMethod3(MyDomainObject object) { }

I cannot call this one from Silverlight, as the method doesn't get generated on the proxy.

Why is it not generated and what can I do about it?


Try adding the [Invoke] attribute to the operation.

I created a sample application defined with the following contract and I was able to have all three methods generated in the Silverlight application.

Here is the DBML file.

RIA method does not appear in Silverlight

Here is the defined service.

[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;
    }
}

And this was the generated code in the Silverlight project:

/// <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

精彩评论

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