locked
OperationContract - updating object instances on the client RRS feed

  • Question

  • I am new to WCF and was wondering if someone could point me in the right direction.

    I’ve defined an OperationContract, but when I use the service my code just seems far from elegant and I am sure there must be a better way.

    My OperationContract takes a collection of tasks to perform returning a collection of processed tasks.

    I want to maintain the original task instances so I end up with something like:

     

    List<Task> processedTasks = Process(orignalTasks);

     

    //Update the original task instance

    For (int index = 0; index < processedTasks.count; index++)

    {

    // Hack to maintain the original instance

    originalTasks[index].RefreshState(processedTasks[index])
    }

     

    Surely there is an easier way?

    Thanks

    Rich


    Richard J
    Saturday, November 27, 2010 4:23 PM

Answers

  • Hi Rich,

    So far the WCF programming model will use serialization for transfer rich objects. It won't like trandtional remoting that transfer objects as reference(MarshalByRef object).  For your case, it is possible that you define some lightweight wrapper object for those rich task objects(simply contains some identity properties such as TaskID). And your service operations simply pass such wrapper objects over wire and return back. And at client, you can reassociate the wrapper object and update the changes into the actual objects at client-side.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by RichJ79 Monday, November 29, 2010 11:04 AM
    Monday, November 29, 2010 8:03 AM

All replies

  • You cannot keep the exact same object reference - it goes through serialization which creates a new object. You might decide to use the processedTasks and forget about the original if possible.
    http://webservices20.blogspot.com/
    WCF Security, Interoperability And Performance Blog
    Saturday, November 27, 2010 4:50 PM
  • Thanks for the reply - appreciates its all down to deserialisation creating a new object.

    Unfortunately I am working with a legacy system where there could be numerous obj references that would need updating to the new obj.   I suppose I was kind of wondering whether there is any WCF behaviours/support or patterns that could help out.   But sounds like this isn't the case then...

     

     


    Richard J
    Sunday, November 28, 2010 9:27 PM
  • Hi Rich,

    So far the WCF programming model will use serialization for transfer rich objects. It won't like trandtional remoting that transfer objects as reference(MarshalByRef object).  For your case, it is possible that you define some lightweight wrapper object for those rich task objects(simply contains some identity properties such as TaskID). And your service operations simply pass such wrapper objects over wire and return back. And at client, you can reassociate the wrapper object and update the changes into the actual objects at client-side.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by RichJ79 Monday, November 29, 2010 11:04 AM
    Monday, November 29, 2010 8:03 AM