This project is read-only.
2
Vote

Inheritance of DataContract classes does not work

description

If I add the following code to IWsdlSample.cs:
 
 
/// <summary>
/// Implements a inheritor.
/// </summary>
[DataContract]
public class Inheritor : DataContractSample
{
    /// <summary>
    /// Gets or sets the property.
    /// </summary>
    /// <value>The property.</value>
    [DataMember]
    public string Property
    {
        get;
        set;
    }
}
 
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

comments

perlun wrote Jul 7, 2009 at 8: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 8:16 PM

gsommer wrote Jul 8, 2009 at 12:54 PM

Per,

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,
Gerhard

jd2400 wrote Sep 29, 2010 at 1: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 8: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:
[KnownType(typeof(Inheritor))]
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 9: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:sequence>
<xsd:element minOccurs="0" name="Property" nillable="true" type="xsd:string">
<xsd:annotation>
<xsd:appinfo/>
<xsd:documentation>
<summary> Gets or sets the property. </summary> <value>The property.</value>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

wrote Nov 24, 2012 at 11:32 AM

wrote Feb 21, 2013 at 11:53 PM