Inheritance of DataContract classes does not work


If I add the following code to IWsdlSample.cs:
/// <summary>
/// Implements a inheritor.
/// </summary>
public class Inheritor : DataContractSample
    /// <summary>
    /// Gets or sets the property.
    /// </summary>
    /// <value>The property.</value>
    public string Property
and reference Inheritor instead of DataContractSample in the first parameter of Operation2, the proxy classes are not generated anymore by Update Service References in the sample client.
The same problem occurs, when I just declare [KnownType(typeof(Inheritor))] in the definition of DataContractSample, to force WCF to include Inheritor in the WSDL.

file attachments


perlun wrote Jul 7, 2009 at 7:16 PM

This patch fixes this problem. Works fine for me. Should be applied using GNU patch (can be found here if you don't have it already: http://gnuwin32.sourceforge.net/packages/patch.htm)

Apply it like this: patch -p1 < file.diff (while standing one directory above the WCFExtras folder, and having the diff in a file called file.diff in that folder).

wrote Jul 7, 2009 at 7:16 PM

gsommer wrote Jul 8, 2009 at 11:54 AM


thank You very much for this patch. Now WCFExtras works almost as it should.
I am still wondering, why base classes, that are only used for inhertitance and not elsewhere in the code, are not documented. But this is not a really important problem.

Best Regards,

jd2400 wrote Sep 29, 2010 at 12:52 PM

This is a big problem for me and I guess the patch will solve my problems. Please supply me with a more detailed way of using this patch. Is it the WCFExtras.dll I need to use?

GiannisKhan wrote Nov 24, 2012 at 7:49 AM

The patch proposed is very usefull, but it concerns only the import process during proxy class generation.
If I add the code posted by gsommer and then I decorate the DataContractSample with the attribute:
comments for the Inheritor data-contract won't be exported to wsdl any more.
So somethings goes wrong in the Export process!
Debugging a little bit I found that method
object IDataContractSurrogate.GetCustomDataToExport(Type clrType, Type dataContractType)
in XmlCommentsDataSurrogate class, get invoked with parameter dataContractType = typeof(DataContractSample), but it never get called with parameter dataContractType = typeof(Inheritor).
Can anybody help me with any ideas?

GiannisKhan wrote Nov 24, 2012 at 8:20 AM

Related to my last post:
if could help the wsdl created for Inherit data-contract is
<xsd:complexType name="Inheritor">
<xsd:complexContent mixed="false">
<xsd:extension base="tns:DataContractSample">
<xsd:element minOccurs="0" name="Property" nillable="true" type="xsd:string">
<summary> Gets or sets the property. </summary> <value>The property.</value>

wrote Nov 24, 2012 at 10:32 AM

wrote Feb 21, 2013 at 10:53 PM