salesforce apex class call exteral webservice
在项目中需要调用外面的Webservice, 从Salesforce往外写入其他系统。目前一般有两种方法。
1. 根据对方提供的wsdl文件生成apex class,直接实例化后调用其方法(测试成功),包括Java 和 .Net不同的平台提供的wsdl文件。
2.直接用HttpRequest去调用webservice.
下面就是参考这位朋友的博客,测试成功的案例。
http://www.cnblogs.com/yqskj/archive/2013/04/25/3041781.html
HttpRequest req = new HttpRequest();
//Set HTTPRequest Method
req.setMethod('POST');
req.setEndpoint('https://api.authorize.net/soap/v1/Service.asmx');
req.setMethod('POST');
req.setHeader('Content-Type', 'text/xml; charset=utf-8');
req.setHeader('SOAPAction', 'https://api.authorize.net/soap/v1/CreateCustomerProfile');//
string b = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'+
'<soap:Body><CreateCustomerProfile xmlns="https://api.authorize.net/soap/v1/">'+
'<merchantAuthentication><name>Merchant name here</name>'+
'<transactionKey>Transaction Key here</transactionKey></merchantAuthentication>'+
'<profile><description>description</description>'+
'<email>sforce2009@gmail.com</email>'+
'<paymentProfiles>'+
'<CustomerPaymentProfileType><customerType>individual</customerType>'+
'<payment><creditCard><cardNumber>6011000000000012</cardNumber>'+
'<expirationDate>2009-12</expirationDate></creditCard>'+
'</payment></CustomerPaymentProfileType></paymentProfiles></profile>'+
'</CreateCustomerProfile></soap:Body></soap:Envelope>';
req.setBody(b);
Http http = new Http();
try {
//Execute web service call here
HTTPResponse res = http.send(req);
//Helpful debug messages
System.debug(res.toString());
System.debug('STATUS:'+res.getStatus());
System.debug('STATUS_CODE:'+res.getStatusCode());
//YOU CAN ALWAYS PARSE THE RESPONSE XML USING XmlStreamReader CLASS
} catch(System.CalloutException e) {
//Exception handling goes here....
}
http://blog.giovannimodica.com/post/call-a-net-wcf-service-from-salesforce
第一种方案,在最近的项目中,遇到一些问题,记录下来,给大家一个参考。
1.对方的wsdl文件打开后,要用SingleWsdl;
2.点击从Wsdl导入生产Apex类的时候一般会报错,请不要慌,一个一个解决;
a)Attribute error. 直接把报错的attribute的报错节点去掉;
b)salesforce目前不支持Soap12. 直接把soap12 header去掉,保留一个soap,替代所有已用的"soap12" 节点为 "soap".
salesforce apex class call exteral webservice的更多相关文章
- Salesforce Apex 使用JSON数据的示例程序
本文介绍了一个在Salesforce Apex中使用JSON数据的示例程序, 该示例程序由以下几部分组成: 1) Album.cls, 定了了封装相关字段的数据Model类 2) RestClient ...
- Salesforce Apex页面中调用远端网络服务
本文介绍了Salesforce Apex页面中调用远端网络服务的实现过程. ### 注册远端网络服务 在使用Apex代码调用远端网络服务之前,首先需要在Salesforce中注册远端网络服务地址, 本 ...
- Salesforce Apex 开发环境设置和Hello World示例
本文介绍了Salesforce Apex开发环境的设置以及一个简单的Hello World示例的实现过程. Salesforce开发环境 Salesforce通过http://developer.fo ...
- Salesforce apex标签的有关内容
局部刷新标签: apex:actionSupport event="onchange" action="{!changeSelect}" rerender=&q ...
- Salesforce Apex学习 : 利用Schema命名空间中的DescribeSObjectResult类型来获取sObject对象的基本信息
DescribeSObjectResult 对象的取得: //使用getDescribe方法和sObject token Schema.DescribeSObjectResult mySObjDesc ...
- Salesforce LWC学习(三十五) 使用 REST API实现不写Apex的批量创建/更新数据
本篇参考: https://developer.salesforce.com/docs/atlas.en-us.224.0.api_rest.meta/api_rest/resources_compo ...
- salesforce 零基础学习(三十三)通过REST方式访问外部数据以及JAVA通过rest方式访问salesforce
本篇参考Trail教程: https://developer.salesforce.com/trailhead/force_com_dev_intermediate/apex_integration_ ...
- salesforce
salesforce&apex salesforce开发的小心得 salesforce零基础学习(七十七)队列的实现以及应用 摘要: 队列和栈简单的区别为栈是后进先出,队列是先进先出.队列也是 ...
- Salesforce LWC学习(四) 父子component交互 / component声明周期管理 / 事件处理
我们在上篇介绍了 @track / @api的区别.在父子 component中,针对api类型的变量,如果声明以后就只允许在parent修改,son component修改便会导致报错. sonIt ...
随机推荐
- 2017-2018年Scrum状态调查报告
HOW SCRUM IS USED 在2017年的报告中,Scrum的应用范围在扩大,已经从其发源的IT部门扩展到了相距甚远的业务部门.2017-2018年度报告的其中一个主要目标就是关注更广泛的敏捷 ...
- mybatis bug之org.apache.ibatis.exceptions.PersistenceException:
详细报错信息: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java. ...
- java 学习必备的软件,持续更新中
小编会持续更新在学习Java过程中需要的软件以及各种文件: 话不多说,看行动! 一:JDK (1)JDK1.8(*64): 链接:https://pan.baidu.com/s/1vM0jNXn2CT ...
- .net开源工作流ccflow从表数据数据源导入设置
第1节. 关键字 驰骋工作流引擎 流程快速开发平台 workflow ccflow jflow .net开源工作流 第2节. 从表数据导入设置 1.1.1: 概要说明 在从表的使用中我一般都会用到从 ...
- 小程序应用的Python服务器部署高配,依然是腾讯云秒杀阿里云!
上一篇文章,“小程序创业最低配置部署,腾讯云折扣秒杀阿里云!”介绍了小程序项目启动时的最低配置服务器选择,但当项目良好发展时,还是要把服务器配置调整到标准水平,承受住日益增长的流量访问. 随着Pyth ...
- spring javaconfig druidsource
package dataConfig; import java.sql.SQLException; import org.springframework.context.annotation.Bean ...
- java.sql.SQLException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone.
[报错信息] [百度翻译] 服务器时区值'???ú±ê×??±??'无法识别或表示多个时区.如果要利用时区支持,必须配置服务器或JDBC驱动程序(通过ServerTimeZone配置属性),以使用更具 ...
- Android视频录制从不入门到入门系列教程(三)————视频方向
运行Android视频录制从不入门到入门系列教程(二)————显示视频图像中的Demo后,我们应该能发现视频的方向是错误的. 由于Android中,Camera给我们的视频图片的原始方向是下图这个样子 ...
- Jmeter Beanshell 用法
Beanshell 的用法 什么是beanshell Beanshell是一种完全符合java语法的脚本语言,并且拥有自己的内置对象和语法 Beanshell是用java写的,一个小型嵌入式java源 ...
- 『C编程』学习笔记(1)
size_t类型详解: #include <cstddef> #include <iostream> #include <array> int main() { s ...