Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should WCF DataContracts be value or reference types?

You're at the service's end of the wire and you don't know your clients.

Why would you choose one over the other?

like image 456
user134706 Avatar asked Jul 13 '09 12:07

user134706


2 Answers

As a rule of thumb; when designing a type yourself it should be a class, unless the type represents a single value, in which case it should be a struct.

like image 186
Fredrik Mörk Avatar answered Sep 24 '22 01:09

Fredrik Mörk


Fredrik has the correct answer. I'll only add that you should keep in mind that the client will never see your Data Contract. It will be translated into XML Schema and will be included in the WSDL. On the client side, recall, it could be a Perl or even Classic ASP client - something that has no concept of value vs. reference semantics.

So value vs. reference is something that only matters to the service - not to the clients.

like image 40
John Saunders Avatar answered Sep 26 '22 01:09

John Saunders