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文件的测试。
问题整理:
- 与SAP集成的时候 遇到 ‘SOAPFault: soapenv:VersionMismatch Error’
System.HttpResponse[Status=Internal Server Error, StatusCode=500]
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"><soap-env:Header/><soap-env:Body><soap-env:Fault><faultcode>soap-env:VersionMismatch</faultcode><faultstring xml:lang="en">Wrong SOAP Version</faultstring><detail/></soap-env:Fault></soap-env:Body></soap-env:Envelope>
解决方案:
It is the issue with the “xmlns:soap” value “http://schemas.xmlsoap.org/soap/envelope/” ,Instead of this you can use “http://www.w3.org/2003/05/soap-envelope” which will solve your issue .
SOAP versioning is based on XML namespaces. SOAP 1.1 is identified by the schemas.xmlsoap.org namespace while SOAP 1.2 is identified by the second one.
参考链接:https://stackoverflow.com/questions/26233636/soapfault-soapenvversionmismatch-error
代码样例:
[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