locked
How Do I add service operations that take Entities as parameters RRS feed

  • Question

  • I'd like to have some business logic in my Data Service class.
    Specifically I'd like to take Entity as parameter and then perform some custom data operations with it (beyond CRUD)
    However I can not see an easy way to add
    void PerformSomeOperation(Customer customer)
    {
    }

    method.

    Doing either [WebGet] or [WebInvoke] in front of it produces following error:

    The exception message is 'Method 'Void PerformSomeOperation (BusinessLayerEntities.Customer)' has a parameter 'BusinessLayerEntities.Customer customer' of type 'BusinessLayerEntities.Customer' which is not supported for service operations. Only primitive types are supported as parameters


    Thursday, December 18, 2008 10:29 PM

Answers

  • I can only think of two approaches until v2:

    1) Send the key, then lookup the Customer by key and do your stuff.  In some cases you don't need to send all the customer fields anyway, so sending a whole customer is overhead.

    2) For Inserts, I think you could probably serialize the type on the client side into a string and pass that.  The deserialize on server side and do you crud.

    Not ideal, but may get you down the road.
    • Marked as answer by MichaelF77 Saturday, December 20, 2008 2:46 AM
    Friday, December 19, 2008 2:11 AM

All replies

  • Something we are looking at for V2, but not in V1.

    You can hack around this by defining paramaters for all the members of the Entity type.  Not nice, but may work in limited scenarios.
    Friday, December 19, 2008 1:04 AM
    Moderator
  • What is recommended way to handle the scenario until v2 is released ? Separate WCF service ?

    The problem is that if I add separate WCF service (even to the same project) the entities between the two are not compatible even though they are one and the same :(

    Friday, December 19, 2008 1:08 AM
  • I found following workaround:

    - Implement custom Entity that has Key - Link to Entity I'd like to pass as parameter and some parameters, specifically: CustomerUpdate entity, has unique ID and CustomerID field

    - Implement custom ChangeInterceptor for CustomerUpdateSet

    - On the client side associate Customer with CustomerUpdate entity, update both and SaveChange(batch)

    In the interceptor I now have loaded object with data from client that I can use to perform whatever action.

    Is that an acceptable way ?
    Friday, December 19, 2008 2:08 AM
  • I can only think of two approaches until v2:

    1) Send the key, then lookup the Customer by key and do your stuff.  In some cases you don't need to send all the customer fields anyway, so sending a whole customer is overhead.

    2) For Inserts, I think you could probably serialize the type on the client side into a string and pass that.  The deserialize on server side and do you crud.

    Not ideal, but may get you down the road.
    • Marked as answer by MichaelF77 Saturday, December 20, 2008 2:46 AM
    Friday, December 19, 2008 2:11 AM