{"id":4458,"date":"2014-03-30T11:14:19","date_gmt":"2014-03-30T11:14:19","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/wcf-messagecontract-datacontract-confused-collection-of-common-programming-errors\/"},"modified":"2014-03-30T11:14:19","modified_gmt":"2014-03-30T11:14:19","slug":"wcf-messagecontract-datacontract-confused-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/wcf-messagecontract-datacontract-confused-collection-of-common-programming-errors\/","title":{"rendered":"WCF: MessageContract, DataContract &hellip; Confused?-Collection of common programming errors"},"content":{"rendered":"<p>Re the request\/response &#8211; a <code>[DataContract]<\/code> would work just as well. One of the advantages of message-contracts is that you can set privacy against members, but in many cases this isn&#8217;t necessary. In such cases, I prefer to keep the contract as simple as possible, just as a data-contract.<\/p>\n<p>Re which serializer &#8211; that is largely a factor of the configuration. By default over http, for example, it will be <code>DataContractSerializer<\/code>.<\/p>\n<p>I&#8217;m not sure, however, that the list of <code>IMyComplexType<\/code> is going to work very well. You could try, but generally it wants concrete types. Note that with base-classes you can use <code>[KnownType]<\/code> to specify the allowed sub-types.<\/p>\n<p>Note that unlike <code>XmlSerializer<\/code>, it is not a requirement for collection members to have setters &#8211; although you might need to add an <code>OnDeserializing<\/code> callback method to initialize the list if you do that (WCF doesn&#8217;t call constructors).<\/p>\n<p>Aside: you can also use protobuf-net with data-contracts and WCF (as long as they have an explicit Order); this is more densely packed than the regular xml. It has no support for message-contracts at the moment, though.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Re the request\/response &#8211; a [DataContract] would work just as well. One of the advantages of message-contracts is that you can set privacy against members, but in many cases this isn&#8217;t necessary. In such cases, I prefer to keep the contract as simple as possible, just as a data-contract. Re which serializer &#8211; that is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4458","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4458"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4458\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}