2010-12-08 103 views
11

我想知道Salesforce用來調用遠程Web服務的invoke方法的參數。我有一個服務,我可以調用,但服務WSDL沒有定義安全要求,所以我希望我可以手動添加這些信息(服務使用通過Soap頭傳遞的WS-Security)。Salesforce WebServiceCallout.invoke方法的參數是什麼?

這是我(我認爲)到目前爲止知道:

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 
); 

誰能幫助填補空白?

回答

16

這裏是我迄今發現的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 
} 

此外,SOAP頭可以通過在SERVICEPORT類創建對象以及 使用同一個變量名稱的String插入+ 「_hns」指定的命名空間爲該對象:

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> 

的頂點類將是這樣的:

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 [] eg 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> 

的apex_schema_type_info陣列指定關於由類所表示的XML元素的信息: 1.架構 2. '真',如果將elementFormDefault = 「合格」 3。'真'如果attributeFormDefault =「合格」

我仍然相當模糊2和3實際上做什麼,但它似乎影響子元素(和屬性)如何繼承父命名空間(無論是暗示的還是必須的在生成的XML中指定)。

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

請隨時糾正或澄清...

+0

你找到了一種方法來生成`酒吧`請求XML? @Jeremy – Jair 2014-02-21 15:20:22

5

還有就是Force.com Apex Code Developers Guide - Understanding the Generated Code,但它是目前爲WebServiceCallout.invoke(...)細節相當稀少。

還有Apex Web Services and Callouts,再次沒有任何有用的細節。

最終投票Ideas: Documentation for WebServiceCallout可能有助於長遠。


的Salesforce剛剛做wsdl2apex的Github上一個開源版本,所以您現在可以檢查代碼,看看到底是什麼發生。 Announcing the Open-Source WSDL2Apex Generator

相關問題