SOAP API System Integration (SFDC to other system)

SFDC通过SOAP API和其他系统集成有两种方式,
一种是将对方系统提供的wsdl文件导入到系统中,生成对应的apex code,而后通过调用apex code实现系统集成。
另外一种方式是,sfdc发送http请求,实现集成。样例代码如下:

HttpRequest req = new HttpRequest();
String url = 'yourdomain.com';
req.setEndpoint(url);
String username = 'yourusernmae';
String password = 'yourpassword';

Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'Basic ' +
EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
String rquestBody = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:crm="your custom name space url' +
'<soapenv:Header/>' +
'<soapenv:Body>' +
  '<!--your defined custom object schemas-->' +
'</soapenv:Body>' +
'</soapenv:Envelope>';
req.setMethod('POST');
req.setHeader('Content-Type','text/xml;charset=UTF-8');
req.setHeader('SOAPAction', URL);
req.setHeader('User-Agent','Jakarta Commons-HttpClient/3.1');
req.setBody(rquestBody); 
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());

在实现该功能前,可以参考w3c提供的文档,学习一下SOAP的报文格式。
可以通过SOAPUI完成wsdl文件的测试。

代码样例:
[1] https://developer.salesforce.com/forums/?id=906F00000008zPZIAY

SOAP xml 样例 包括对象结构
[2] https://developer.salesforce.com/page/Sample_SOAP_Messages-create
[3] https://developer.salesforce.com/blogs/developer-relations/2015/06/salesforce-soap-api-sample-wsdls.html

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页