2

I have generated WSDL2Apex code from this wsdl, however, it is not putting namespaces on elements that need it.

This is what SF Generates and is incorrect:

<env:Body>
    <Search xmlns="http://api.cvent.com/2006-11">
        <ObjectType>Event</ObjectType>
        <CvSearchObject>
            <Filter xmlns="http://schemas.cvent.com/api/2006-11">
                <Field>EventTitle</Field>
                <Operator>Contains</Operator>
                <Value>calg</Value>
            </Filter>
        </CvSearchObject>
    </Search>
</env:Body>

This is what it needs to be (notice the namespace declaration on CvSearchObject):

<env:Body>
    <Search xmlns="http://api.cvent.com/2006-11">
        <ObjectType>Event</ObjectType>
        <CvSearchObject xmlns="http://schemas.cvent.com/api/2006-11">
            <Filter xmlns="http://schemas.cvent.com/api/2006-11">
                <Field>EventTitle</Field>
                <Operator>Contains</Operator>
                <Value>calg</Value>
            </Filter>
        </CvSearchObject>
    </Search>
</env:Body>

Here is the current generated code:

public class Search_element {
    public String ObjectType;
    public schemasCventComApi200611.CvSearch CvSearchObject;
    private String[] ObjectType_type_info = new String[]{'ObjectType','http://api.cvent.com/2006-11',null,'1','1','false'};
    private String[] CvSearchObject_type_info = new String[]{'CvSearchObject','http://schemas.cvent.com/api/2006-11',null,'0','1','false'};
    private String[] apex_schema_type_info = new String[]{'http://api.cvent.com/2006-11','true','false'};
    private String[] field_order_type_info = new String[]{'ObjectType','CvSearchObject'};
}

How would I go about forcing the namespace on that element? I have tried modifying the generate code but to no avail.

6
  • What are you expecting people do to here? If you feel this is a bug, the right path would be to open a ticket with Support. Sep 6 '16 at 15:16
  • I'm expecting people to look at the WSDL, and generated Apex Code, to see if there is a way to force the namespace to show up on the CvSearchObject element Sep 6 '16 at 15:21
  • Once wsdl2Apex generates the code, you can change it manually if it somehow doesn't adhere to what you need. In any case, your question is completely unclear. I recommend you edit the text to clearly explain what your expectations are. For reference, check the How to Ask page. Sep 6 '16 at 15:22
  • Made some edits Sep 6 '16 at 16:51
  • This open source wsdl2apex might work better or allow you to infer more about the purpose of the *_type_info arrays.
    – Keith C
    Sep 6 '16 at 17:45
3

WSDL to Apex doesn't support referencing elements from a different namespace:

Apex also supports the following schema constructs:

  • xsd:all, in Apex code saved using API version 15.0 and later
  • xsd:annotation, in Apex code saved using API version 15.0 and later
  • xsd:attribute, in Apex code saved using API version 15.0 and later
  • xsd:choice, in Apex code saved using API version 15.0 and later
  • xsd:element. In Apex code saved using API version 15.0 and later, the ref attribute is also supported with the following restrictions:
    • You cannot call a ref in a different namespace.

Document about the wsdl 2 apex: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex.htm

So if you cannot change the element's namespace, the other alternative is to rely on a regular HTTP callout (as opposed to an Apex web service callout)

Info/links about HTTP callouts:

0

It appears that WebServiceCallout.invoke isn't going to pickup the correct namespace for the CvSearchObject from the CvSearchObject_type_info even if you correct it.

E.g.

private String[] CvSearchObject_type_info = new String[]{'CvSearchObject','http://schemas.cvent.com/api/2006-11','','0','1','false'};

I took a slightly different approach to generate the required request. Using the the FuseIT SFDC Explorer WSDL2Apex implementation I generated an HTTP request from the WSDL. (Disclosure: This is my current employer and a free tool I work on). To do this use the drop down next to the Search method and select "SOAP and HTTP"

enter image description here

To correct the CVSearchObject namespace the following line in Search_x_element needed to be changed from:

Dom.XmlNode CvSearchObjectNode = outerNode.addChildElement('CvSearchObject', 'http://api.cvent.com/2006-11', '');

to

Dom.XmlNode CvSearchObjectNode = outerNode.addChildElement('CvSearchObject', 'http://schemas.cvent.com/api/2006-11', '');

Now the following anonymous apex:

apiCventCom200611.V200611Soap cvent = new apiCventCom200611.V200611Soap();
schemasCventComApi200611.CvSearch so = new schemasCventComApi200611.CvSearch();

schemasCventComApi200611.Filter filter = new schemasCventComApi200611.Filter();
filter.Field='EventTitle';
filter.Operator='Contains';
filter.Value='calg';

so.Filter = new schemasCventComApi200611.Filter[0];
so.Filter.add(filter);

schemasCventComApi200611.SearchResult sr = cvent.Search_x_Http('Event', so);

Produces the expected SOAP message:

<?xml version="1.0" encoding="utf-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Header xmlns="http://schemas.xmlsoap.org/soap/envelope/" />
  <Body xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Search xmlns="http://api.cvent.com/2006-11">
      <ObjectType>Event</ObjectType>
      <CvSearchObject xmlns="http://schemas.cvent.com/api/2006-11">
        <Filter>
          <Field>EventTitle</Field>
          <Operator>Contains</Operator>
          <Value>calg</Value>
          <ValueArray />
        </Filter>
        <SearchType></SearchType>
      </CvSearchObject>
    </Search>
  </Body>
</env:Envelope>

If time permits I'll revisit the WSDL to see if I can get it to generate with the correct namespace initially.

3
  • Thanks for looking into this. My main question is, is salesforce just squashing the namespace reference because it's parent node has a namespace? Sep 6 '16 at 22:32
  • Unfortunately the internals of WebServiceCallout.invoke are still a black box. In the ideal world it would be using the namespace indicated by the CvSearchObject_type_info to set the namespace for the CvSearchObject element. However, as you have found, it appears to be ignored and just stays in the parents namespace. Do you have access to Salesforce support to raise this as a case? Sep 6 '16 at 23:12
  • I do not have access to Salesforce Support. I only was able to create a forum post Sep 8 '16 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.