Salesforce调用外部的webservice接口

一、上篇讲了如何将webservice接口生成wsdl并且部署到远程服务器上。外网可进行访问。

先将wsdl文件进行下载,然后再将wsdl导入到SF中。通过在Develop->Apex Classes中

然后点击下一步,可以得到下图

然后再去生成apex的代码。会生成两个类。AsyncWeb 一个是异步调用 web 一个是同步调用 要在远程站点设置访问的url

注意:此url要能够在外网也能访问,否则接口就调用不通

1public class AsyncWeb { 2 public class sendOAResponseFuture extends System.WebServiceCalloutFuture { 3 public Boolean getValue() { 4 web.sendOAResponse response = (web.sendOAResponse)System.WebServiceCallout.endInvoke(this); 5 return response.return_x; 6 } 7 } 8 public class AsyncSendServiceImplPort { 9 public String endpoint_x = 'http://远程主机IP:8080/CXFWebservice/webservice/sendServie'; 10 public Map<String,String> inputHttpHeaders_x; 11 public String clientCertName_x; 12 public Integer timeout_x; 13 private String[] ns_map_type_info = new String[]{'http://siyuan.com/', 'web'}; 14 public AsyncWeb.sendOAResponseFuture beginSendOA(System.Continuation continuation,String param) { 15 web.sendOA request_x = new web.sendOA(); 16 request_x.param = param; 17 return (AsyncWeb.sendOAResponseFuture) System.WebServiceCallout.beginInvoke( 18 this, 19 request_x, 20 AsyncWeb.sendOAResponseFuture.class, 21 continuation, 22 new String[]{endpoint_x, 23 '', 24 'http://siyuan.com/', 25 'sendOA', 26 'http://siyuan.com/', 27 'sendOAResponse', 28 'web.sendOAResponse'} 29 ); 30 } 31 } 32} 33 34public class web { 35 public class sendOAResponse { 36 public Boolean return_x; 37 private String[] return_x_type_info = new String[]{'return','http://siyuan.com/',null,'1','1','false'}; 38 private String[] apex_schema_type_info = new String[]{'http://siyuan.com/','false','false'}; 39 private String[] field_order_type_info = new String[]{'return_x'}; 40 } 41 public class sendOA { 42 public String param; 43 private String[] param_type_info = new String[]{'param','http://siyuan.com/',null,'0','1','false'}; 44 private String[] apex_schema_type_info = new String[]{'http://siyuan.com/','false','false'}; 45 private String[] field_order_type_info = new String[]{'param'}; 46 } 47 public class SendServiceImplPort { 48 public String endpoint_x = 'http://远程主机IP:8080/CXFWebservice/webservice/sendServie'; 49 public Map<String,String> inputHttpHeaders_x; 50 public Map<String,String> outputHttpHeaders_x; 51 public String clientCertName_x; 52 public String clientCert_x; 53 public String clientCertPasswd_x; 54 public Integer timeout_x; 55 private String[] ns_map_type_info = new String[]{'http://siyuan.com/', 'web'}; 56 public Boolean sendOA(String param) { 57 web.sendOA request_x = new web.sendOA(); 58 request_x.param = param; 59 web.sendOAResponse response_x; 60 Map<String, web.sendOAResponse> response_map_x = new Map<String, web.sendOAResponse>(); 61 response_map_x.put('response_x', response_x); 62 WebServiceCallout.invoke( 63 this, 64 request_x, 65 response_map_x, 66 new String[]{endpoint_x, 67 '', 68 'http://siyuan.com/', 69 'sendOA', 70 'http://siyuan.com/', 71 'sendOAResponse', 72 'web.sendOAResponse'} 73 ); 74 response_x = response_map_x.get('response_x'); 75 return response_x.return_x; 76 } 77 } 78}

然后再在匿名类中,进行接口调用

1web.SendServiceImplPort us = new web.SendServiceImplPort(); 2us.sendOA('hello ss'); 3System.debug('mess'+us.sendOA('hello ss'));

可以看到是调用成功的了

也输出了信息

现在去远程的服务器上看调用的一些打印信息

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )