4

我正在尝试将 WSDL 导入 Salesforce,其中 XML 元素之一包含元素和字符串值,例如

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

当我使用 WSDL 到 Apex 工具将其导入时,字符串值在生成的类中不可用——只有属性。

这是 WSDL 片段:

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

生成的类是:

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[]{};
}

有没有办法可以手动修改此类以提供没有内部元素的值?

4

2 回答 2

3

正如您所注意到的,WSDL2Apex 不正确支持 xs:extension(它不在http://www.salesforce.com/us/developer/docs/apexcode/salesforce_apex_language_reference.pdf第 201 页上支持的 WSDL 功能列表中)。

将生成的类更改为如下所示:

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[]{};
}

您可能还必须更改为您的 SOAP 操作生成的方法以允许此额外参数 - 这取决于您的 WSDL 的外观。

于 2010-12-22T01:55:24.977 回答
0

底层WebServiceCallout.invoke不支持也具有属性的简单类型的扩展。你可以有一个或另一个,但不能同时拥有。

我制作了免费的FuseIT SFDC Explorer工具,其中包括 Wsdl2Apex 的替代版本。这包括在 Apex 中生成原始 HttpRequest 和相应的 SOAP XML 消息的选项。有了这个,您可以调用所需的 Web 方法。

于 2015-07-31T09:17:55.617 回答