function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SlachtermanSlachterman 

Modifying Wsdl2Apex Generated Classes to Handle xs:extension and imported namespaces

I am having trouble with wsdl2apex code generation, mainly due to the use of xs:import namespace and xs:extension in my WSDL.

In particular, I am seeing the error System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element . . .. The raw SOAP response returned by the web service looks as I would expect.

I would like to modify the generated Apex classes to work around this issue, as server-side changes to the web service is not an option.

The SOAP response looks like the below:

 

<ns:getAccountsResponse>
 <ns:return xsi:type="ax1:AccountReturn">
  <ax2:successful>true</ax2:successful>
  <ax2:transactionId>1000</ax2:transactionId>
  <ax1:Accounts xsi:type="ax1:Account">

 

And the WSDL looks like this for the ax1 target namespace:

 

<xs:complexType name="AccountReturn">
 <xs:complexContent>
  <xs:extension base="ax100:BaseReturnObject">
   <xs:sequence>
    <xs:element maxOccurs="unbounded" minOccurs="0" name="Accounts" nillable="true" type="ax1:Account"/>
   </xs:sequence>
  </xs:extension>
 </xs:complexContent>
</xs:complexType>

 
And for the ax2 target namespace:

<xs:complexType name="BaseReturnObject">
 <xs:sequence>
  <xs:element minOccurs="0" name="successful" type="xs:boolean"/>
  <xs:element minOccurs="0" name="transactionId" nillable="true" type="xs:integer"/>
 </xs:sequence>
</xs:complexType>

 

The generated Apex Class which maps to AccountReturn only contains the fields for Accounts in ax1, but not the BaseReturnObject fields in ax2, since the wsdl2apex generation does not respect the use of xs:extension or the importing of namespaces (based on my research).

Is there anyway to modify the Apex Class to make this work? I tried adding the fields from BaseReturnObject to AccountReturn, and modifying field_order_type_info. However, it appears that apex_schema_type_info can only point to one namespace, and this may be the reason that the parsing of the callout response is still failing.

Alex Packard 12Alex Packard 12
Sure wish this had an answer...