Salesforce WebServiceCallout.invoke方法的参数是什么?

Jer*_*emy 13 api salesforce callouts

我想知道Salesforce用于调用远程Web服务的invoke方法的参数.我有一个服务,我可以调用,但服务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
);
Run Code Online (Sandbox Code Playgroud)

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

Jer*_*emy 20

这是我到目前为止为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
}
Run Code Online (Sandbox Code Playgroud)

此外,可以通过在servicePort类中创建对象以及具有相同变量名+"_ hns"的String来插入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";
Run Code Online (Sandbox Code Playgroud)

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

给出以下示例XML:

<foo a="b"><bar>baz</bar></foo>
Run Code Online (Sandbox Code Playgroud)

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'};
   }
}
Run Code Online (Sandbox Code Playgroud)

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

如果变量表示另一个XML元素或文本节点,则需要匹配_type_info String [],例如bar_type_info.这个数组的元素是:1.XML元素名称2.模式3. XML类型4. minOccurs 5. maxOccurs(无限制设置为'-1')6.isNillable

如果变量表示属性,则必须存在匹配的_att_info String [],例如a_type_info.这只包含属性的XML名称.

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

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

<foo bar="baz">bar</foo>
Run Code Online (Sandbox Code Playgroud)

所述apex_schema_type_info阵列指定关于由类所表示的XML元素信息:1.架构2."真",如果将elementFormDefault ="合格" 3."真",如果attributeFormDefault ="合格"

我还是什么2和3实际上做的相当模糊,但似乎影响到子元素(和属性)如何继承父命名空间(无论是暗示或必须在生成的XML指定).

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

请随时纠正或澄清......


Dan*_*ger 7

有一个Force.com Apex代码开发人员指南 - 了解生成的代码,但它的细节目前相当稀少WebServiceCallout.invoke(...).

还有Apex Web服务和标注,也没有任何有用的细节.

向上投票的想法:从长远来看,WebServiceCallout的文档可能会有所帮助.


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