13

我想知道 Salesforce 用来调用远程 Web 服务的调用方法的参数。我有一个我应该能够调用的服务,但是服务 WSDL 没有定义安全要求,所以我希望我可以手动添加该信息(服务使用通过 Soap 标头传递的 WS-Security)。

这是我(认为我)到目前为止所知道的:

WebServiceCallout.invoke(
  Class servicePort, //Usually set to "this", contains httpheader info as well as ? 
  request_x, //Request object, defining schema, properties, and field order
  response_map_x, //Response object, defining schema, properties, and field order
  new String[]{
  String endpoint, //Endpoint of the service
  String ?, //what is this?
  String methodSchema, //Schema for the request object?
  String method, //Name of the request method?
  String responseSchema, //Schema for the response object?
  String response, //Name of the response object?
  String responseClass} //Name of the Apex class the response will be converted to
);

任何人都可以帮助填补空白吗?

4

2 回答 2

24

以下是我迄今为止对 WebServiceCallout.invoke 的发现:

Object servicePort - A class with the following variables:
  String enpoint_x: containing the service endpoint (not sure if necessary)
  Map<String,String> inputHttpHeaders_x: custom httpHeaders
  Map<String,String> outputHttpHeaders_x: I think this is the httpHeaders that were returned
  String clientCertName_x: Used in configuring an SSL cert?
  String clientCert_x: Used in configuring an SSL cert?
  String clientCertPassword: Used in configuring an SSL cert?
  Integer timeout_x: How long (in milliseconds?) to wait for the response
  String[] ns_map_type_info: The first String is the namespace of the service schema, the second is the name of the object that contains the Apex classes defining the schema objects
Object request_x - The Apex object that will form the XML schema object
Map<String, Object> response_map_x - Object is the object that the result is to be unserialized into. String is the name of Object variable.
String[] {
  endpoint - The service endpoint
  soapAction - If the service call requires a soapAction, put it here. Otherwise leave blank.
  methodSchema - Schema for the request object
  method - Name of the request method
  responseSchema Schema for the response
  responseClass The Apex class that the response will be unserialized into
}

此外,可以通过在 servicePort 类中创建一个对象以及一个具有相同变量名称+“_hns”的字符串来插入 Soap 标头,该变量指定该对象的命名空间:

public SoapSecurity Security;
private String Security_hns = "Security=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";

顶点 XML 模式对象应包含每个子元素(或属性)的变量。变量名称与特定模式匹配的数组定义了对象变量在 xml 中的使用方式。

给定以下示例 XML:

<foo a="b"><bar>baz</bar></foo>

Apex 类将是这样的:

public class MyService {
   public class bar {
      public String bar;
      private String[] bar_type_info = new String[] {'bar','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
      private String[] apex_schema_type_info = new String[] {'http://schema.myservice.com', 'false', 'false'};
      private String[] field_order_type_info = new String[] {'bar'};
   }

   public class foo {
      public MyService.bar bar;
      public String a;
      private String[] bar_type_info = new String[] {'bar','http://schema.myservice.com','bar','0','1','true'};
      private String[] a_att_info = new String[] {'a'};
      private String apex_schema_type_info = new String[] {'http://schema.myservice.com','false','false'};
      private String[] field_order_type_info = new String[] {'bar'};
   }
}

以下是这些对象的(简要)细分:

如果变量代表另一个 XML 元素或文本节点,则需要有一个匹配的 _type_info String[],例如 bar_type_info。该数组的元素是: 1. XML 元素名称 2. Schema 3. XML 类型 4. minOccurs 5. maxOccurs(设置为“-1”表示无界) 6. isNillable

如果变量代表一个属性,那么必须有一个匹配的_att_info String[] 例如a_type_info。Thise 仅包含属性的 XML 名称。

请注意,如果类变量名称是保留字,则将 _x 附加到其上,例如 bar_x。这会影响其他变量名称:bar_x_type_info。Apex 开发人员指南解释了他们的名称规则,但如果您手动创建它,我认为您可以给它任何您想要的名称——数组确定 XML 元素名称......

我还没有找到一种方法来表示还包含一个属性的简单 XML 类型:例如

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

apex_schema_type_info 数组指定类所表示的 XML 元素的相关信息: 1. Schema 2. 如果 elementFormDefault="qualified" 则为 'true' 3. 如果 attributeFormDefault="qualified" 则为'true'

对于 2 和 3 的实际作用,我仍然很模糊,但它似乎会影响子元素(和属性)如何继承父命名空间(无论是隐含的还是必须在生成的 XML 中指定)。

field_order_type_info 只是指定子元素的顺序。

请随时纠正或澄清...

于 2010-12-16T17:45:58.743 回答
7

Force.com Apex 代码开发人员指南 - 了解生成的代码,但目前关于WebServiceCallout.invoke(...).

还有Apex Web Services 和 Callouts,同样没有任何有用的细节。

投票建议:WebServiceCallout 的文档从长远来看可能会有所帮助。


Salesforce 刚刚在 Github 上发布了 wsdl2apex 的开源版本,因此您现在可以检查代码以确切了解发生了什么。宣布开源 WSDL2Apex 生成器

于 2011-04-08T00:56:15.610 回答