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 ...
随机推荐
- 遍历 Map 的四种方法
public static void main(String[] args) { Map<String, String> map = new HashMap<String, Stri ...
- Writing a Simple Publisher and Subscriber
用c++实现一个publisher/subscriber publisher #include "ros/ros.h" #include "std_msgs/String ...
- 从0开始用U盘制作启动盘装Windows10系统(联想R720笔记本)并永久激活方法
一,制作U盘启动盘 随着个人电脑的“飞入寻常百姓家”,喜欢DIY电脑的发烧友们也越来越多. 安装系统是DIY最基本的要求,很容易做到: 那么如果要求用U盘装系统呢,你可能会说简单,直接下载个老毛桃或是 ...
- SharePoint中你不知道的图片库(实战)
分享人:广州华软 无名 一. 前言 以前,在门户网站放一个图片幻灯片时,除了要自己开发实现外,还需要处理上传图片的大小,但在SharePoint中,使用图片库,无需花费时间和精力,就能马上实现. 二. ...
- Fragment与Fragment相互切换之间的生命周期方法
Fragment 1 切换到 Fragment 2时生命周期变化 1.通过 add hide show 方式来切换 Fragment Fragment1 的生命周期变化为:onCreate().onC ...
- 每天五分钟-javascript数据类型
javascript数据类型分为基本数据类型与复杂数据类型 基本数据类型包括:string,number,boolean,null,undefined,symbol(es6) 复杂数据类型包括:obj ...
- HttpClient 报错 Invalid cookie header, Invalid 'expires' attribute: Thu, 01 Jan 1970 00:00:00 GMT
今天在给我姐夫写一个 QQ 自动加好友的程序,但是在 HttpClient 登陆 QQ 的时候报了一个错: -- ::] - Invalid cookie header: Jan :: GMT -- ...
- dom4j创建和解析xml文档
DOM4J解析 特征: 1.JDOM的一种智能分支,它合并了许多超出基本XML文档表示的功能. 2.它使用接口和抽象基本类方法. 3.具有性能优异.灵活性好.功能强大和极端易用的特点. 4.是一个开 ...
- cent os 7 与cent os 6 修改主机名称
centos6 需要修改两处:一处是/etc/sysconfig/network,另一处是/etc/hosts,只修改任一处会导致系统启动异常.零时修改用hostname your-name cnet ...
- 基于mysql的一些sql语法
Sql: distinct: select distinct * from tea; Tea中每行的数据必有不同,若有两行相同的,则只输出一行 Limit: select * from stu lim ...