views:

17

answers:

1

In our domain, we override the ToString method on all our domain types.

However, when returning those domain objects in response to a Silverlight service request, the functionality of ToString is lost. ToString() just returns the namespace description of the object as it is imported from the service. My guess is that the domain proxy created by the service reference doesn't include the ToString logic.

Is it possible to get this to work without having to re-implement ToString on the Silverlight client?

Update: BTW, this is so I can bind to the whole object and have the string description honored. I have a collection of domain objects coming back from a service. I would like to set the ItemsSource of a UI collection to a list of these domain objects and not have to re-create the ToString logic locally.

+1  A: 

The proxy doesn't generate a member part for the contract for the ToString() method, because ToString() isn't part of the ServiceContract. Not just that though, I'm not confident that the proxy classes that are generated, intelligently override Object.ToString() when they are created. Could you not add a descriptive method, something like GetDescription() which will be created in the proxy?

If not, could you not just override the method in the proxy (it should be generated as a partial) and provide a client-specific implementation?

Matthew Abbott
@Matthew Yeah, I can override it in the client, but we have many objects this would need to be applied to. It would be a bit painful to have 30 domain objects defined in a nice layer and then to duplicate part of their logic on the client. I was hoping ToString would work because that is what binding uses to display. I want to bind to the entire object (for ItemsSource) and not have to provide a data template to get the string property I need (which might be just what I have to do).
j0rd4n