在项目中需要调用外面的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的更多相关文章

  1. Salesforce Apex 使用JSON数据的示例程序

    本文介绍了一个在Salesforce Apex中使用JSON数据的示例程序, 该示例程序由以下几部分组成: 1) Album.cls, 定了了封装相关字段的数据Model类 2) RestClient ...

  2. Salesforce Apex页面中调用远端网络服务

    本文介绍了Salesforce Apex页面中调用远端网络服务的实现过程. ### 注册远端网络服务 在使用Apex代码调用远端网络服务之前,首先需要在Salesforce中注册远端网络服务地址, 本 ...

  3. Salesforce Apex 开发环境设置和Hello World示例

    本文介绍了Salesforce Apex开发环境的设置以及一个简单的Hello World示例的实现过程. Salesforce开发环境 Salesforce通过http://developer.fo ...

  4. Salesforce apex标签的有关内容

    局部刷新标签: apex:actionSupport event="onchange" action="{!changeSelect}" rerender=&q ...

  5. Salesforce Apex学习 : 利用Schema命名空间中的DescribeSObjectResult类型来获取sObject对象的基本信息

    DescribeSObjectResult 对象的取得: //使用getDescribe方法和sObject token Schema.DescribeSObjectResult mySObjDesc ...

  6. Salesforce LWC学习(三十五) 使用 REST API实现不写Apex的批量创建/更新数据

    本篇参考: https://developer.salesforce.com/docs/atlas.en-us.224.0.api_rest.meta/api_rest/resources_compo ...

  7. salesforce 零基础学习(三十三)通过REST方式访问外部数据以及JAVA通过rest方式访问salesforce

    本篇参考Trail教程: https://developer.salesforce.com/trailhead/force_com_dev_intermediate/apex_integration_ ...

  8. salesforce

    salesforce&apex salesforce开发的小心得 salesforce零基础学习(七十七)队列的实现以及应用 摘要: 队列和栈简单的区别为栈是后进先出,队列是先进先出.队列也是 ...

  9. Salesforce LWC学习(四) 父子component交互 / component声明周期管理 / 事件处理

    我们在上篇介绍了 @track / @api的区别.在父子 component中,针对api类型的变量,如果声明以后就只允许在parent修改,son component修改便会导致报错. sonIt ...

随机推荐

  1. JAVA 探究NIO

    事情的开始 1.4版本开始,java提供了另一套IO系统,称为NIO,(New I/O的意思),NIO支持面向缓冲区的.基于通道的IO操作. 1.7版本的时候,java对NIO系统进行了极大的扩展,增 ...

  2. Docker进阶之一:Docker介绍与体系结构

    一.  Docker是什么 Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源,基于Linux内核的cgroup,namespace,Union FS 等技术, ...

  3. c#上位机与三菱PLC(FX3U)串口通讯

    项目中会经常用到上位机与PLC之间的串口通信,本文介绍一下C#如何编写上位机代码 与三菱FX3U进行通讯 1. 第一种方法是自己写代码实现,主要代码如下: //对PLC的Y7进行置1 byte[] Y ...

  4. 数据结构——Java实现单链表

    一.分析 单链表是一种链式存取的数据结构,用一组地址任意的存储单元存放线性表中的数据元素.链表中的数据是以结点来表示的,每个结点由元素和指针构成.在Java中,我们可以将单链表定义成一个类,单链表的基 ...

  5. wkhtmltox实现网页转换成图片或pdf

    1.先下载http://download.gna.org/wkhtmltopdf/obsolete/windows/wkhtmltox-0.11.0_rc1-installer.exe,安装 2.在命 ...

  6. Vue.js实现登录功能

    编写html,通过vue-resource.js库向后台提交数据 <!DOCTYPE html> <html lang="en"> <head> ...

  7. 对于python爬虫urllib库的一些理解(抽空更新)

    urllib库是Python中一个最基本的网络请求库.可以模拟浏览器的行为,向指定的服务器发送一个请求,并可以保存服务器返回的数据. urlopen函数: 在Python3的urllib库中,所有和网 ...

  8. Ext.isIterable

    Ext.isIterable用于判断传入的参数是否为可迭代的 在这4种情况下,函数返回true 1:数组2:函数参数arguments3:HTML collections : NodeList4:HT ...

  9. W3C 代码标准规范

    W3C通过设立领域(Domains)和标准计划(Activities)来组织W3C的标准活动,围绕每个标准计划,会设立相关的W3C工作组织(包括工作组.社区组.商务组等).W3C会根据产业界的标准需求 ...

  10. Django 项目中添加静态文件夹

    在 mysite 文件夹下添加一个 statics 文件夹用来存放 js 文件 在 index.html 文件中添加 <!DOCTYPE html> <html lang=" ...