Note that there are some explanatory texts on larger screens.

plurals
  1. POWindows Azure: Serializing an object that is inherited by TableServiceEntity
    primarykey
    data
    text
    <p>I want to have this class serialized, so i can send it as the body of a httpresponsemessage:</p> <pre><code> [DataContract] public class Subscription : TableServiceEntity { [DataMember] public string SubscriptionId { get; set; } [DataMember] public bool IsAdmin { get; set; } } </code></pre> <p>The way i want to use it:</p> <pre><code> IList&lt;Subscription&gt; subs = ... ; return new HttpResponseMessage&lt;IList&lt;Subscription&gt;&gt;(subs); </code></pre> <p>It compiles, but when i run this part i get an error saying the IList can't be serialized and i have to add it to the known type collection. I'm guessing the members of TableServiceEntity are not serializable and that's why i can't serialize the whole list in all, but i don't know how to resolve this issue.</p> <p>Any ideas?</p> <p>Sincerely,</p> <p>Zoli</p> <p><strong>MODIFICATION</strong></p> <p>I added a new class just as it was said in the first comment and it looks like this:</p> <pre><code> [DataServiceEntity] [DataContract] [KnownType(typeof(Subscription))] public abstract class SerializableTableServiceEntity { [DataMember] public string PartitionKey { get; set; } [DataMember] public string RowKey { get; set; } [DataMember] public DateTime Timestamp { get; set; } } [DataContract] public class Subscription : SerializableTableServiceEntity { [DataMember] public string SubscriptionId { get; set; } [DataMember] public bool IsAdmin { get; set; } } </code></pre> <p>I still get the error saying to</p> <blockquote> <pre><code>add type to known type collection and to use the serviceknowntypeattribute before the operations </code></pre> </blockquote> <p>the only operation i use is this:</p> <pre><code>public class DBModelServiceContext : TableServiceContext { public DBModelServiceContext(string baseAddress, StorageCredentials credentials) : base(baseAddress, credentials) { } public IList&lt;Subscription&gt; Subscriptions { get { return this.CreateQuery&lt;Subscription&gt;("Subscriptions").ToArray(); } } } </code></pre> <p><strong>MODIFICATION 2</strong></p> <p>MY interface looks like this:</p> <pre><code> [OperationContract] [ServiceKnownType(typeof(IList&lt;Subscription&gt;))] [WebGet(UriTemplate = "subscription/{value}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] HttpResponseMessage&lt;IList&lt;Subscription&gt;&gt; GetSubscription(string value); </code></pre> <p>the implementation behind is:</p> <pre><code> public HttpResponseMessage&lt;IList&lt;Subscription&gt;&gt; GetSubscription(string value) { var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"); var context = new DBModelServiceContext(account.TableEndpoint.ToString(), account.Credentials); IList&lt;Subscription&gt; subs = context.Subscriptions; return new HttpResponseMessage&lt;IList&lt;Subscription&gt;&gt;(subs);} </code></pre>
    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.
    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