none
svcutil and complexContent extensions RRS feed

  • Question

  • Generating a servicedefiniton from wsdl via svcutil where the xsd contains complex types that derive via complexcontent extensions elements the resulting data classes sometimes contain no members at all.

    Sample wsdl (extensiontest.wsdl):

    <?xml version="1.0" encoding="UTF-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.org/extensiontest" xmlns:t="http://example.org/extensiontest"> <xs:complexType name="Base"> <xs:sequence> <xs:element name="A" type="xs:string" /> </xs:sequence> </xs:complexType> <xs:complexType name="Extension"> <xs:complexContent> <xs:extension base="t:Base"> <xs:sequence> <xs:element name="B" type="xs:string" minOccurs="0" nillable="true" /> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:element name="Test" type="t:Extension" /> <!-- <xs:element name="TestResponse" type="xs:string" /> --> <xs:element name="TestResponse"> <xs:complexType> <xs:sequence> <xs:element name="C" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>

    and xsd (extensiontest.xsd):

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema attributeFormDefault="unqualified"
        elementFormDefault="qualified"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://example.org/extensiontest"
        xmlns:t="http://example.org/extensiontest">
    
        <xs:complexType name="Base">
            <xs:sequence>
                <xs:element name="A" type="xs:string" />
            </xs:sequence>
        </xs:complexType>
    
        <xs:complexType name="Extension">
            <xs:complexContent>
                <xs:extension base="t:Base">
                    <xs:sequence>
                        <xs:element name="B" type="xs:string" minOccurs="0" nillable="true" />
                    </xs:sequence>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
    
        <xs:element name="Test" type="t:Extension" />
        <!-- <xs:element name="TestResponse" type="xs:string" /> -->
        <xs:element name="TestResponse">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="C" type="xs:string" />
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:schema>

    Generating serivce code from this service definition via "svcutil /sc extensiontest.wsdl extensiontest.xsd" results in an empty request class:

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
    public partial class TestRequest
    {
        
        [System.ServiceModel.MessageBodyMemberAttribute(Name="Test", Namespace="http://example.org/extensiontest", Order=0)]
        public TestRequestBody Body;
        
        public TestRequest()
        {
        }
        
        public TestRequest(TestRequestBody Body)
        {
            this.Body = Body;
        }
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    [System.Runtime.Serialization.DataContractAttribute()]
    public partial class TestRequestBody
    {
        
        public TestRequestBody()
        {
        }
    }

    Interestingly when I change the return type to simple type (by swapping the comment on the last two <xs:element> in the xsd) svcutil generates a correct request class that has the A and B members:

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/extensiontest")]
    public partial class Extension : Base
    {
        
        private string bField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(IsNullable=true, Order=0)]
        public string B
        {
            get
            {
                return this.bField;
            }
            set
            {
                this.bField = value;
            }
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(Extension))]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/extensiontest")]
    public partial class Base
    {
        
        private string aField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=0)]
        public string A
        {
            get
            {
                return this.aField;
            }
            set
            {
                this.aField = value;
            }
        }
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
    public partial class TestRequest
    {
        
        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://example.org/extensiontest", Order=0)]
        public Extension Test;
        
        public TestRequest()
        {
        }
        
        public TestRequest(Extension Test)
        {
            this.Test = Test;
        }
    }

    Is this a known problem, and if yes are there any workarounds?

    Or am I even using something that is not supported in wcf? At least the msdn page on DataContract schemas ( http://msdn.microsoft.com/en-us/library/ms733112%28v=vs.110%29.aspx#sectionToggle29 since my account isn't veryfied yet) seems to agree with me that this should be possible.

    Thursday, August 7, 2014 6:18 PM

Answers

  • Hi,

    First please try to use the "Add Service Reference" to generate the proxy to see if it helps.

    Then maybe you need to add the [KnownType(typeof(YourType)] attribute to your class this will tell the proxy generator what types is the service using and according to that it should generate the right class for you everytime.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, August 11, 2014 3:11 AM
    Moderator