tags:

views:

168

answers:

2

I have an object I pass to a WCF service. Then on the server, the service modifies some properties of the object, and returns an int.

On the client side, after the service is called, the changes made to the objects' properties are not there.

My unit tests work fine. But when run over services, the problem occurs.

Any ideas on how to fix this?

+2  A: 

When you pass something over the service boundary it's being passed by value not by reference so any changes made on the server will not propagate to the object you passed from the client. So you would want to return the modified object back to the client. If you also need to return the int you can create a wrapper class that can contain both the int and the changed object.

olle
Thanks. I was hoping there might be an attribute to fix this, but that makes sense.
A: 

@jodogger, maybe I'm missing something but if the service returns an int, it certainly won't change your object.

The problem is that your object never actually makes the round trip to the server. Because of the disconnected nature of WCF, you must pass values byval and not byref.

If you must change values in the WCF service, you'll need to do something like this:

myObject = WCFService.MethodName(myObject);

That isn't actually the same object coming back, but you'll be clobbering your old object with the new values of that object.

Please note that the object being returned will need to be created by you in the DataContract section of the interface as well as the implementation itself.

Rap