question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataContract containing IList<struct> produces invalid WSDL

See original GitHub issue

If you have a DataContract containing a property of type IList<T> where T is a struct, the WSDL that is generated is invalid.

Example

    [ServiceContract]
    public interface IMyService
    {
        [OperationContract]
        void Do(DTO input);
    }

    public class MyService : IMyService
    {
        public void Do(DTO input)
        {
        }
    }

    [DataContract]
    public class DTO
    {
        [DataMember]
        public IList<AnyStruct> MyStructs { get; set; }
    }

    [DataContract]
    public struct AnyStruct
    {
    }

The code above will yield the following WSDL.

Please note the name attribute has no value.

<xs:complexType xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" name="ArrayOfAnyStruct">
   <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="" type="xs:"/>
   </xs:sequence>
</xs:complexType>

Adding a [FaultContract(typeof(InvalidOperationException))] attribute will also cause this behavior.

The WSDL cannot be imported into the WCF Test Client or Visual Studio 2019. Given that in the actual problem case, I do not own the type, is there any way around this?

Thanks in advance, -Bart

Full WSDL

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:http="http://schemas.microsoft.com/ws/06/2004/policy/http" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://tempuri.org/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://tempuri.org/" name="MyService">
   <wsdl:types>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
         <xs:import namespace="http://schemas.datacontract.org/2004/07/WebApplication1.Service" />
         <xs:element name="Do">
            <xs:complexType>
               <xs:sequence>
                  <xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/WebApplication1.Service" minOccurs="0" name="input" nillable="true" type="q1:DTO" />
               </xs:sequence>
            </xs:complexType>
         </xs:element>
         <xs:element name="DoResponse">
            <xs:complexType>
               <xs:sequence />
            </xs:complexType>
         </xs:element>
      </xs:schema>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
         <xs:element name="anyType" nillable="true" type="xs:anyType" />
         <xs:element name="anyURI" nillable="true" type="xs:anyURI" />
         <xs:element name="base64Binary" nillable="true" type="xs:base64Binary" />
         <xs:element name="boolean" nillable="true" type="xs:boolean" />
         <xs:element name="byte" nillable="true" type="xs:byte" />
         <xs:element name="dateTime" nillable="true" type="xs:dateTime" />
         <xs:element name="decimal" nillable="true" type="xs:decimal" />
         <xs:element name="double" nillable="true" type="xs:double" />
         <xs:element name="float" nillable="true" type="xs:float" />
         <xs:element name="int" nillable="true" type="xs:int" />
         <xs:element name="long" nillable="true" type="xs:long" />
         <xs:element name="QName" nillable="true" type="xs:QName" />
         <xs:element name="short" nillable="true" type="xs:short" />
         <xs:element name="string" nillable="true" type="xs:string" />
         <xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte" />
         <xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt" />
         <xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong" />
         <xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort" />
         <xs:element name="char" nillable="true" type="tns:char" />
         <xs:simpleType name="char">
            <xs:restriction base="xs:int" />
         </xs:simpleType>
         <xs:element name="duration" nillable="true" type="tns:duration" />
         <xs:simpleType name="duration">
            <xs:restriction base="xs:duration">
               <xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?" />
               <xs:minInclusive value="-P10675199DT2H48M5.4775808S" />
               <xs:maxInclusive value="P10675199DT2H48M5.4775807S" />
            </xs:restriction>
         </xs:simpleType>
         <xs:element name="guid" nillable="true" type="tns:guid" />
         <xs:simpleType name="guid">
            <xs:restriction base="xs:string">
               <xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}" />
            </xs:restriction>
         </xs:simpleType>
         <xs:attribute name="FactoryType" type="xs:QName" />
         <xs:attribute name="Id" type="xs:ID" />
         <xs:attribute name="Ref" type="xs:IDREF" />
      </xs:schema>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:tns="http://schemas.datacontract.org/2004/07/WebApplication1.Service" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/WebApplication1.Service">
         <xs:import namespace="http://schemas.datacontract.org/2004/07/System" />
         <xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
         <xs:complexType name="DTO">
            <xs:sequence>
               <xs:element minOccurs="0" name="MyStructs" nillable="true" type="tns:ArrayOfAnyStruct" />
            </xs:sequence>
         </xs:complexType>
         <xs:element name="DTO" nillable="true" type="tns:DTO" />
         <xs:complexType name="ArrayOfAnyStruct">
            <xs:sequence>
               <xs:element minOccurs="0" maxOccurs="unbounded" name="" type="xs:" />
            </xs:sequence>
         </xs:complexType>
         <xs:element name="ArrayOfAnyStruct" nillable="true" type="tns:ArrayOfAnyStruct" />
         <xs:complexType name="AnyStruct">
            <xs:sequence />
         </xs:complexType>
         <xs:element name="AnyStruct" nillable="true" type="tns:AnyStruct" />
      </xs:schema>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
         <xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
      </xs:schema>
   </wsdl:types>
   <wsdl:message name="IMyService_Do_InputMessage">
      <wsdl:part name="parameters" element="tns:Do" />
   </wsdl:message>
   <wsdl:message name="IMyService_Do_OutputMessage">
      <wsdl:part name="parameters" element="tns:DoResponse" />
   </wsdl:message>
   <wsdl:portType name="IMyService">
      <wsdl:operation name="Do">
         <wsdl:input wsam:Action="http://tempuri.org/IMyService/Do" message="tns:IMyService_Do_InputMessage" />
         <wsdl:output wsam:Action="http://tempuri.org/IMyService/DoResponse" message="tns:IMyService_Do_OutputMessage" />
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="BasicHttpBinding" type="tns:IMyService">
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
      <wsdl:operation name="Do">
         <soap:operation soapAction="http://tempuri.org/IMyService/Do" style="document" />
         <wsdl:input>
            <soap:body use="literal" />
         </wsdl:input>
         <wsdl:output>
            <soap:body use="literal" />
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="MyService">
      <wsdl:port name="BasicHttpBinding" binding="tns:BasicHttpBinding">
         <soap:address location="http://localhost:5000/MyService.svc" />
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
bartbovendeerdtcommented, Feb 26, 2020

@kotovaleksandr No, it still comes back with an error.

Invalid name character in 'xmlns:q1'. The ':' character, hexadecimal value 0x3A, cannot be included in a name.
0reactions
github-actions[bot]commented, Aug 27, 2021

This issue was closed because it has been inactive for 14 days since being marked as stale.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid WSDL generated? - SOAP
The root of the problem appears to be that the WSDL and XSD seem to expect certain types (typically array types) to be...
Read more >
DataContract containing Array[] produces invalid WSDL #401
Hi, I was faced with the problem of incorrect generation of wsdl, it consists in the fact that when creating an array, an...
Read more >
Why do I get System.InvalidOperationException back from ...
Well, the error is pretty clear: System.Runtime.Serialization.InvalidDataContractException: Type 'Pariwaar.BusinessObject.
Read more >
DataContractAttribute Class (System.Runtime.Serialization)
Specifies that the type defines or implements a data contract and is serializable by a serializer, such as the DataContractSerializer.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found