Salesforce WSDL import of simpleContent w/extensio

2020-07-17 15:59发布

I am attempting to import a WSDL into Salesforce where one of the XML elements contains both an element and a string value e.g.

 <foo bar="bob">baz</foo>

When I import this using the WSDL to Apex tool, the string value is not available in the generated class--just the attribute.

Here is the WSDL snippet:

 <xs:complexType name="password">
   <xs:simpleContent>
     <xs:extension base="xs:string">
       <xs:attribute name="Type" type="xs:string"/>
     </xs:extension>
   </xs:simpleContent>
 </xs:complexType>

The generated class is:

public class password {
  public String Type_x;
  private String[] Type_x_att_info = new String[]{'Type'};
  private String[] apex_schema_type_info = new String[]{'http://schema.test.org/1_0','false','false'};
  private String[] field_order_type_info = new String[]{};
}

Is there a way I can manually modify this class to provide a value without an inner element?

2条回答
戒情不戒烟
2楼-- · 2020-07-17 16:12

The underlying WebServiceCallout.invoke doesn't support extensions of simple types that also have attributes. You can have one or the other, but not both.

I've made the free FuseIT SFDC Explorer tool, which includes an alternative version of Wsdl2Apex. This includes an option to generate the raw HttpRequest and corresponding SOAP XML message in Apex. With this you can call the required web method.

查看更多
劫难
3楼-- · 2020-07-17 16:16

As you've noticed, WSDL2Apex doesn't support xs:extension correctly (it's not in the list of supported WSDL features on page 201 of http://www.salesforce.com/us/developer/docs/apexcode/salesforce_apex_language_reference.pdf).

Change your generated class to look something like:

public class password {
  public String input;
  public String Type_x;
  private String[] input_type_info = new String[]{'input','http://www.w3.org/2001/XMLSchema','string','1','1','false'}; // change 'input' to be the desired name of your element
  private String[] Type_x_att_info = new String[]{'Type'};
  private String[] apex_schema_type_info = new String[]{'http://schema.test.org/1_0','false','false'};
  private String[] field_order_type_info = new String[]{};
}

You may also have to change the method generated for your SOAP operation to allow for this extra parameter - it depends on what your WSDL looks like.

查看更多
登录 后发表回答