Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for serializing extension types #209

Merged
merged 1 commit into from
Mar 8, 2019

Conversation

agpreynolds
Copy link
Contributor

@agpreynolds agpreynolds commented Mar 8, 2019

Addresses #206

Add section to WriteComplexType method to add an xs:complexContent section to complex types with base types.

Tweak the method of property discovery - now only properties defined in a class are serialized to that class, inherited properties will be serialized via inheritance.

This means the following class structure and service definition:

[ServiceContract]
    public interface ITestService
    {
        [OperationContract]
        Cat GetCat();

        [OperationContract]
        Dog GetDog();
    }
public abstract class Animal
    {
        public Guid RequestId { get; set; }
        public Group Group { get; set; }
    }

    public class Cat : Animal
    {
        public string Name { get; set; }
    }

    public class Dog : Animal
    {
        public string Name { get; set; }
        public Breed Breed { get; set; }
    }

    public enum Breed { Terrier, Hound, Puppy }
    public enum Group { Mammal, Amphibian, Reptile }

Produces the following WSDL classes:

<xs:complexType xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" name="Cat">
<xs:complexContent>
<xs:extension base="tns:Animal">
<xs:sequence>
<xs:element minOccurs="0" name="Name" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Cat" nillable="true" type="tns:Cat"/>
<xs:complexType xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" name="Dog">
<xs:complexContent>
<xs:extension base="tns:Animal">
<xs:sequence>
<xs:element nillable="true" type="tns:Breed" name="Breed"/>
<xs:element minOccurs="0" name="Name" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Dog" nillable="true" type="tns:Dog"/>

Only bit i'm not happy with is the method of detecting a root class, type.BaseType.Name != "Object" seems a bit rubbish

@kotovaleksandr kotovaleksandr merged commit bf99dad into DigDes:master Mar 8, 2019
@agpreynolds
Copy link
Contributor Author

Hi, out of interest what type is being written that has a base type of null? I will add the null check and raise another PR

@psalmnoelff
Copy link

Hi guys, i was trying this feature out but it seems that its not being rendered as complex types in the xml/wsdl. Is there a config where I need to enabled this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants