locked
Can I access ServiceOperations in Silverlight 2 Beta 2 using the Client proxy RRS feed

  • Question

  • I have a very simple DataService defined with a [WebGet] Service Operation:

     

    public class WebDataService : DataService<NorthwindEntities>

    {

    // This method is called only once to initialize service-wide policies.

    public static void InitializeService(IDataServiceConfiguration config)

    {

    config.SetEntitySetAccessRule("*", EntitySetRights.All);

    config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);

    }

     

    [WebGet]

    public IQueryable<Customers> CustomersByCity(string city)

    {

    if (string.IsNullOrEmpty(city))

    {

    throw new ArgumentNullException("city", "You must provide a type name argument");

    }

     

    return from c in this.CurrentDataSource.Customers

    where c.City == city

    select c;

    }

    }

     

    I have then generated a Silverlight client proxy using the datasvcutil.exe.

     

    How would I use this proxy to access my CustomersByCity operation, is it possible? It looks like the datasvcutil.exe only generates against the entities defined in the service, not service operations. Is this true?

     

    Thanks

    Richie

    Wednesday, July 9, 2008 3:57 PM

Answers

  •  

    Hi Richie,

     The Client Code generated by astoria  does not include service operations , but you can call the operations by using the CreateQuery option and passing the parameters in using the AddQueryOption API ,

    an example would be :

     

     

    Code Snippet

    ClientContext ctx = new ClientContext(<URIToService>);

    DataServiceQuery<Customers> dsqServiceOp =  ctx.CreateQuery<Customers>("CustomersByCity").AddQueryOption("city","'London'");

     

    dsqServiceOp.BeginExecute( queryFinishedCallback , dsqServiceOp );

     

    private void queryFinishedCallback(IAsyncResult asyncResult){

     DataServiceQuery<Customers> dsqServiceOp = asyncResult.AsyncState as  DataServiceQuery<Customers>;

     

    if( dsqServiceOp  != null ){

    var Results =   dsqServiceOp.EndExecute(asyncResult);
    }

    }

     

     

    Wednesday, July 9, 2008 11:47 PM
    Moderator