+ Start a Discussion
DFW DudeDFW Dude 

Reserve words in WSDL wsdl2apex

I am generating apex from a wsdl using wsdl2apex.  The wsdl has complex data type that contains an Apex reserve word "Map"

 

<complexType name="Map">

<sequence>

<element maxOccurs="unbounded" minOccurs="0" name="item" type="apachesoap:mapItem"/>

</sequence>

</complexType>

 

This generates a class in apex:

 

 public class Map {

public ntta_login.mapItem[] item;

private String[] item_type_info = new String[]{'item','http://xml.apache.org/xml-soap','mapItem','0','-1','false'};

private String[] apex_schema_type_info = new String[]{'http://xml.apache.org/xml-soap','true'};

private String[] field_order_type_info = new String[]{'item'};

}

 

Apex validation fails with "unexpected token class" because of the reserve word Map being used.

 

I try chaning the class to Map_x but the callback fails from the webservice with:

service callout failed: Unable to parse callout response. Apex type not found for element item

 

Is there a workaround that I can use besides changing the wsdl definition source system?

Thanks

 

aalbertaalbert
After you changed the class name to Map_x, did you also change the response type to reflect the class name change?
DFW DudeDFW Dude

Thanks for the response.

 

Yes I did change it in the response type as well.

 

 

 

 

 

aalbertaalbert

Can you post the revised Map class and web service that is failing to return the Map object?

 

 

DFW DudeDFW Dude

here are some items from the apex class 

 

//Generated by wsdl2apex

public class ntta_login {
 
 public ntta_login.Map_x authenticate(String username,String password) {
            ntta_login.authenticate_element request_x = new ntta_login.authenticate_element();
            ntta_login.authenticateResponse_element response_x;
            request_x.username = username;
            request_x.password = password;
           
            Map<String, ntta_login.authenticateResponse_element> response_map_x = new Map<String, ntta_login.authenticateResponse_element>();
            response_map_x.put('response_x', response_x);
         
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://components',
              'authenticate',
              'http://components',
              'authenticateResponse',
              'ntta_login.authenticateResponse_element'}
            );

    public class mapItem {
        public String key;
        public String value;
        private String[] key_type_info = new String[]{'key','http://www.w3.org/2001/XMLSchema','anyType','1','1','true'};
        private String[] value_type_info = new String[]{'value','http://www.w3.org/2001/XMLSchema','anyType','1','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://xml.apache.org/xml-soap','true'};
        private String[] field_order_type_info = new String[]{'key','value'};
    }
   
    public class Map_x {
        public ntta_login.mapItem[] item;
        private String[] item_type_info = new String[]{'item','http://xml.apache.org/xml-soap','mapItem','0','-1','false'};
        private String[] apex_schema_type_info = new String[]{'http://xml.apache.org/xml-soap','true'};
        private String[] field_order_type_info = new String[]{'item'};
    }
  
    public class authenticateResponse_element {
        public ntta_login.Map_x authenticateReturn;
        private String[] authenticateReturn_type_info = new String[]{'authenticateReturn','http://xml.apache.org/xml-soap','Map_x','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://components','true'};
        private String[] field_order_type_info = new String[]{'authenticateReturn'};
    }
      
}
testcall
   ntta_login.securitycfc  nl = new ntta_login.securitycfc ();
       ntta_login.Map_x bla =  nl.authenticate('test', 'test');
       System.debug('Login Result loginResult' +bla);
      
       Callout works and returns
       <soapenv:Body>
  <authenticateResponse xmlns="http://components">
   <authenticateReturn xsi:type="ns1:Map" xmlns:ns1="http://xml.apache.org/xml-soap">
    <item xmlns="">
     <key xsi:type="xsd:string">PWDLASTSET</key>
     <value xsi:type="xsd:string"></value>
    </item>
    <item xmlns="">
     <key xsi:type="xsd:string">DN</key>
     <value xsi:type="xsd:string"></value>
    </item>
    <item xmlns="">
     <key xsi:type="xsd:string">MEMBEROF</key>
     <value xsi:type="xsd:string"></value>
    </item>
    <item xmlns="">
     <key xsi:type="xsd:string">USERNAME</key>
     <value xsi:type="xsd:string"></value>
    </item>
    <item xmlns="">
     <key xsi:type="xsd:string">LOCATION</key>
     <value xsi:type="xsd:string"></value>
    </item>
    <item xmlns="">
     <key xsi:type="xsd:string">FULLNAME</key>
     <value xsi:type="xsd:string"></value>
    </item>
    <item xmlns="">
     <key xsi:type="xsd:string">FIRSTNAME</key>
     <value xsi:type="xsd:string"></value>
    </item>
    <item xmlns="">
     <key xsi:type="xsd:string">LASTNAME</key>
     <value xsi:type="xsd:string"></value>
    </item>
    <item xmlns="">
     <key xsi:type="xsd:string">DISPLAYNAME</key>
     <value xsi:type="xsd:string"></value>
    </item>
    <item xmlns="">
     <key xsi:type="xsd:string">ACCOUNTEXPIRES</key>
     <value xsi:type="xsd:string"></value>
    </item>
    <item xmlns="">
     <key xsi:type="xsd:string">EMAIL</key>
     <value xsi:type="xsd:string"></value>
    </item>
    <item xmlns="">
     <key xsi:type="xsd:string">PHONE</key>
     <value xsi:type="xsd:string"></value>
    </item>
   </authenticateReturn>
  </authenticateResponse>
 </soapenv:Body>
</soapenv:Envelope>
with an error

System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element item.

  

 

Thanks!

 

dgrigsbydgrigsby

DFW Dude,

 

I just went down this journey recently, and yes there are lots of "clean up" items.

 

I have done a large post on the subject. Please review and comment on as appropriate.

 

 
or
 

 

1. WSDL - I would highly suggest using a WSDL/XML tool like Atlova XMLSpy (free trial) to examine the Types that are imported. It will allow you to trim down, and integrate the imported (manually - wish they had a merge - going to post that feature request at Atlova) xsd types, etc. I normally work with Visual Studio or Eclipse and they just couldn't get there. It will show you what is in the namespace and what is imported in the WDSL tab visually by color coding.

 

      a. WSDL Apex Class creation Limitations

          -Size of final Apex Class - 100K characters
        -Size of WSDL input - 1Meg
          - No Imports and no implied types from defined named spaces if they contain definitions (xsd which ws-security does).
           -No Attributes (xsd which ws-security does).
           -No annotations (xsd which ws-security does).

           -No multipe bindings (which most do 1 and 12)

 

2. Be prepared to spend some time (read as parse, fix error, rise and repeat) many times

3. Best SF reference I found was Link:

4. In the end, you may find to get it working that the HTTP request and manual soap xml codeup to be the quickest solution to get it running, Twitter and Facebook integrations work this way. It was really faster in the end for me.

5. The post covers both WSDL2APEX and Direct Soap calls via HTTP Request and examples.

6. Using HTTP.REQ and SOAP will ALLOW you to handle responses that are "different" based on web service response.

 

Best Regards,

 

 

David W. Grigsby
Grigsby Consulting LLC
Intellectual Capital for Your Business
484 East Carmel Drive Suite 390
Carmel, IN 46032