Salesforce WSDL malformed

Summary
Generated WSDL for Apex web services does not contain some type definitions after API version 33.0.

Repro
1) Create a new web service class as below:

global class MyWebService {
webService static Id makeContact(String lastName, Account a) {
Contact c = new Contact(lastName = ‘Weissman’, AccountId = a.Id);
insert c;
return c.id;
}
}

2) Go to Setup > Develop > Apex Class and click on the WSDL link. Download the WSDL file

3) Use soapUI or similar to parse this WSDL. Missing type definitions will be reported:

Source: file:\C:\MyWebService.wsdl
Error: type ‘RecordTypesSupported@http://soap.sforce.com/schemas/class/MyWebService‘ not found.
________________________________________
Source: file:\C:\MyWebService.wsdl
Error: type ‘RelationshipReferenceTo@http://soap.sforce.com/schemas/class/MyWebService‘ not found.
________________________________________
Source: file:\C:\MyWebService.wsdl
Error: type ‘JunctionIdListNames@http://soap.sforce.com/schemas/class/MyWebService‘ not found.
________________________________________
Source: file:\C:\MyWebService.wsdl
Error: type ‘SearchLayoutButtonsDisplayed@http://soap.sforce.com/schemas/class/MyWebService‘ not found.
________________________________________
Source: file:\C:\MyWebService.wsdl
Error: type ‘SearchLayoutFieldsDisplayed@http://soap.sforce.com/schemas/class/MyWebService‘ not found.

Workaround
Get missing type definitions from Enterprise WSDL and add them inside the class WSDL’s <xsd:schema> element.

I.e. in 37.0 this means adding below definitions to <xsd:schema elementFormDefault=”qualified” targetNamespace=”http://soap.sforce.com/schemas/class/<className>/<webserviceName>”>:

<xsd:complexType name=”SearchLayoutButtonsDisplayed”>
<xsd:sequence>
<xsd:element name=”applicable” type=”xsd:boolean”/>
<xsd:element name=”buttons” minOccurs=”0″ maxOccurs=”unbounded” type=”tns:SearchLayoutButton”/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name=”SearchLayoutButton”>
<xsd:sequence>
<xsd:element name=”apiName” type=”xsd:string”/>
<xsd:element name=”label” type=”xsd:string”/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name=”SearchLayoutFieldsDisplayed”>
<xsd:sequence>
<xsd:element name=”applicable” type=”xsd:boolean”/>
<xsd:element name=”fields” minOccurs=”0″ maxOccurs=”unbounded” type=”tns:SearchLayoutField”/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name=”SearchLayoutField”>
<xsd:sequence>
<xsd:element name=”apiName” type=”xsd:string”/>
<xsd:element name=”label” type=”xsd:string”/>
<xsd:element name=”sortable” type=”xsd:boolean”/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name=”JunctionIdListNames”>
<xsd:sequence>
<xsd:element name=”names” minOccurs=”0″ maxOccurs=”unbounded” type=”xsd:string”/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name=”RelationshipReferenceTo”>
<xsd:sequence>
<xsd:element name=”referenceTo” minOccurs=”0″ maxOccurs=”unbounded” type=”xsd:string”/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name=”RecordTypesSupported”>
<xsd:sequence>
<xsd:element name=”recordTypeInfos” minOccurs=”0″ maxOccurs=”unbounded” type=”tns:RecordTypeInfo”/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name=”RecordTypeInfo”>
<xsd:sequence>
<xsd:element name=”available” type=”xsd:boolean”/>
<xsd:element name=”defaultRecordTypeMapping” type=”xsd:boolean”/>
<xsd:element name=”master” type=”xsd:boolean”/>
<xsd:element name=”name” type=”xsd:string”/>
<xsd:element name=”recordTypeId” type=”tns:ID” nillable=”true”/>
</xsd:sequence>
</xsd:complexType>