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. 与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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值