cost
cost

Reputation: 4490

Have the server perform post processing on a string before it is returned via a WCF RIA query?

I've read that you can put business rules on the server when dealing with WCF RIA services, but I'm at a loss for how to accomplish what I what. Basically what I have is, there's a string stored in the database that's encrypted. I have a view that returns that column, and I'd like it to be returned to the client unencrypted. I have a standard DomainService Get method

    public IQueryable<qry_ClientList> GetQry_ClientList(Guid Key)
    {
        return this.ObjectContext.qry_ClientList.OrderBy(p => p.ClientCode);
    }

Can someone point me in the right direction how I'd call the decrypt function on that field before it's returned? I have a reason I want to do this in code and not on the server, but I don't go into that here.

Upvotes: 0

Views: 111

Answers (2)

Jozef Benikovsk&#253;
Jozef Benikovsk&#253;

Reputation: 1141

You can do postprocessing by overriding DomainService.Query() method as follows:

public override System.Collections.IEnumerable Query(QueryDescription queryDescription, out IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> validationErrors, out int totalCount)
{
    IEnumerable result = base.Query(queryDescription, out validationErrors, out totalCount);

    // now you have collection with all client query operators applied and
    // you can apply post-processing
    if (queryDescription.Method.Name == "GetQry_ClientList")
    {
        result.OfType<qry_ClientList>().ToList().ForEach(c => Descrypt(c));
    }

    return result;
}

Upvotes: 0

sparks
sparks

Reputation: 1294

Materialize your entities to a list first, run your function, then convert your list back to an IQueryable before returning:

public IQueryable<qry_ClientList> GetQry_ClientList(Guid Key)
{
    List<qry_ClientList> clients = 
        this.ObjectContext.qry_ClientList.OrderBy(p => p.ClientCode).ToList();
    foreach (qry_ClientList c in clients) {
        Decrypt(c);
    }
    return clients.AsQueryable;
}

Upvotes: 0

Related Questions