我正在尝试将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[]{};
}
有没有办法可以手动修改此类以提供没有内部元素的值?
答案 0 :(得分: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的外观。
答案 1 :(得分:0)
基础WebServiceCallout.invoke
不支持也具有属性的简单类型的扩展。你可以有一个,但不能两个。
我已经制作了免费的FuseIT SFDC Explorer工具,其中包括Wsdl2Apex的替代版本。这包括在Apex中生成原始HttpRequest和相应的SOAP XML消息的选项。有了这个,您可以调用所需的Web方法。