前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Salesforce调用外部的webservice接口

Salesforce调用外部的webservice接口

作者头像
故久
发布2020-06-04 15:03:01
1.6K0
发布2020-06-04 15:03:01
举报
文章被收录于专栏:故久故久

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

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

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

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

代码语言:javascript
复制
public class AsyncWeb {
    public class sendOAResponseFuture extends System.WebServiceCalloutFuture {
        public Boolean getValue() {
            web.sendOAResponse response = (web.sendOAResponse)System.WebServiceCallout.endInvoke(this);
            return response.return_x;
        }
    }
    public class AsyncSendServiceImplPort {
        public String endpoint_x = 'http://远程主机IP:8080/CXFWebservice/webservice/sendServie';
        public Map<String,String> inputHttpHeaders_x;
        public String clientCertName_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://siyuan.com/', 'web'};
        public AsyncWeb.sendOAResponseFuture beginSendOA(System.Continuation continuation,String param) {
            web.sendOA request_x = new web.sendOA();
            request_x.param = param;
            return (AsyncWeb.sendOAResponseFuture) System.WebServiceCallout.beginInvoke(
              this,
              request_x,
              AsyncWeb.sendOAResponseFuture.class,
              continuation,
              new String[]{endpoint_x,
              '',
              'http://siyuan.com/',
              'sendOA',
              'http://siyuan.com/',
              'sendOAResponse',
              'web.sendOAResponse'}
            );
        }
    }
}
代码语言:javascript
复制
public class web {
    public class sendOAResponse {
        public Boolean return_x;
        private String[] return_x_type_info = new String[]{'return','http://siyuan.com/',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://siyuan.com/','false','false'};
        private String[] field_order_type_info = new String[]{'return_x'};
    }
    public class sendOA {
        public String param;
        private String[] param_type_info = new String[]{'param','http://siyuan.com/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://siyuan.com/','false','false'};
        private String[] field_order_type_info = new String[]{'param'};
    }
    public class SendServiceImplPort {
        public String endpoint_x = 'http://远程主机IP:8080/CXFWebservice/webservice/sendServie';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://siyuan.com/', 'web'};
        public Boolean sendOA(String param) {
            web.sendOA request_x = new web.sendOA();
            request_x.param = param;
            web.sendOAResponse response_x;
            Map<String, web.sendOAResponse> response_map_x = new Map<String, web.sendOAResponse>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://siyuan.com/',
              'sendOA',
              'http://siyuan.com/',
              'sendOAResponse',
              'web.sendOAResponse'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.return_x;
        }
    }
}

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

代码语言:javascript
复制
web.SendServiceImplPort us = new web.SendServiceImplPort();
us.sendOA('hello ss');
System.debug('mess'+us.sendOA('hello ss'));

可以看到是调用成功的了

也输出了信息

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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档