Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF [DataContract] set/get not getting executed
    primarykey
    data
    text
    <p>I'm a bit new to WCF and I don't think I completely understand what the deal is with DataContracts. I have this 'RequestArray' class:</p> <pre><code>[DataContract] public class RequestArray { private int m_TotalRecords; private RequestRecord[] m_Record; [System.Xml.Serialization.XmlElement] [DataMember] public RequestRecord[] Record { get { return m_Record; } } [DataMember] public int TotalRecords { get { return m_TotalRecords; } set { if (value &gt; 0 &amp;&amp; value &lt;= 100) { m_TotalRecords = value; m_Record = new RequestRecord[value]; for (int i = 0; i &lt; m_TotalRecords; i++) m_Record[i] = new RequestRecord(); } } } } </code></pre> <p>The idea is when the client says <code>requestArray.TotalRecords=6;</code> the Record array will be allocated and initialized (I realize that I'm hiding an implementation behind an assignment, this is out of my control).</p> <p>The problem is that when the client does this, the TotalRecord's set code is not called, breakpoints in the service confirm this as well. Rather, some sort of generic setter has been generated that is called instead. How do I get the client to use my setter instead?</p> <p>EDIT: It looks like I didn't quite get how the [DataContract] works, but it makes sense that the client wouldn't be executing this code. Like I mentioned in a comment, if I 'manually' do the work of the setter, I see that the set code does get executed right when I call the service function.</p> <p>The serialization I'm still uncertain on. The contents of the RequestRecord[] array are not getting carried over. The Record class has setters/getters, I feel like I need a helper function somewhere to help it serialize the whole class.</p> <p>Thanks all for your help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload