Note that there are some explanatory texts on larger screens.

plurals
  1. POAbstract objects collection definition in wcf service
    text
    copied!<p>I have in my DataContract a collection of objects defined as</p> <pre><code>Collection&lt;BaseAbstractObject&gt; </code></pre> <p>which I want to fill up with some inherited objects of type <strong>ClassA</strong>. </p> <p>I'm using Soap UI to create such a request to my service method, but I'll get error <strong><em>"Cannot create an abstract class"</em></strong></p> <p>I have also decorated base class with <strong>[KnownType(ClassA)]</strong> attribute. My xml request looks like this:</p> <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:wcf="http://schemas.datacontract.org/2004/07/WcfService1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;soapenv:Header/&gt; &lt;soapenv:Body&gt; &lt;tem:GetDataUsingDataContract&gt; &lt;tem:composite&gt; &lt;wcf:ClassesCollection&gt; &lt;wcf:BaseClass i:type="ClassA" &gt; &lt;wcf:Id&gt;1&lt;/wcf:Id&gt; &lt;wcf:Name&gt;ClassA&lt;/wcf:Name&gt; &lt;/wcf:BaseClass&gt; &lt;/wcf:ClassesCollection&gt; &lt;/tem:composite&gt; &lt;/tem:GetDataUsingDataContract&gt; &lt;/soapenv:Body&gt; &lt;/soapenv:Envelope&gt; </code></pre> <p>And this is how my DataContracts looks like:</p> <pre><code>[DataContract] public class MyDataContract { public MyDataContract() { ClassesCollection = new Collection&lt;BaseClass&gt;(); } [DataMember] public Collection&lt;BaseClass&gt; ClassesCollection { get; private set; } } [DataContract] [KnownType(typeof(ClassA))] public abstract class BaseClass { [DataMember] public int Id { get; set; } } [DataContract] public class ClassA : BaseClass { [DataMember] public int Name { get; set; } } </code></pre> <p>So what should my request looks like? Or need I add some other attribute to DataContract?</p>
 

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