zoukankan      html  css  js  c++  java
  • 在Salesforce中调用外部系统所提供的的Web Service

    这里需要提供外部service所对应的WSDL文件(Salesforce只支持从本地上传),并且提供的WSDL文件有如下两点要求:

    1):wsdl 文件只能有一个binding,Salesforce是不支持多个binding的

    2):wsdl 文件要包含所有的schema信息,Salesforce是不支持external schema的import的

    接下来便是具体的操作步骤:

    1):按照此目录 Setup --> Build --> Develop --> Apex Classes 找到对应的 Generate from WSDL 按钮,如下图所示

    2):点击上图中的Generate from WSDL按钮,会得到如下视图,点击Browser按钮从本地目录选择相对应的WSDL文件

    3):之后点击下图中的Parse WSDL按钮,会将WSDL转换成Apex的Class文件(如果此处出现URL无法访问的异常,请看第6条的解决方案)

    4):如果没有任何异常出现的话,就可以在下图中填入Apex Class Name了,然后点击Generate Apex code去真正的生成对应的Class文件

    5):在如下图中可以查看我们具体生成的Apex Class文件,之后就可以在对应的Controller里去调用此Class中的方法了(实际上就是call service),具体代码这里就省略了

    6):如果在第3步的时候出现URL无法访问的异常,根据异常信息可以到Remote Site Setting中把WSDL文件中用到URL添加到Salesforce中

    7):当然了在Salesforce中同样可以调用外部所提供的Rest Service,并且调用Rest Service的方式显得更加的简洁。

    简单的调用代码如下所示:

    public void callRestService() {
    
            HttpRequest req = new HttpRequest();
            HttpResponse res = new HttpResponse();
            Http http = new Http();
        
            req.setEndpoint('http://www.thomas-bayer.com/sqlrest/CUSTOMER/18/');
            req.setMethod('GET');
            //req.setHeader('Content-Type', 'application/json');
            //req.setHeader('Accept', 'application/json');
            //req.setBody('');
            req.setCompressed(true); // otherwise we hit a limit of 32000
        
            try {
                res = http.send(req);
                system.debug('-----000001----- successful response: ' + res);
                system.debug('-----000001----- successful response string: ' + res.toString());
                 system.debug('-----000001----- successful response STATUS: '+res.getStatus());
                 system.debug('-----000001----- successful response STATUS_CODE: '+res.getStatusCode());
                 system.debug('-----000001----- successful response Content: ' + res.getBody());
            } catch(System.CalloutException e) {
                System.debug('-----000002----- Callout error: '+ e);
                System.debug('-----000003----- failed response:' + res.toString());
            }
        
        }

     更多细节请看此链接: https://developer.salesforce.com/page/Apex_Web_Services_and_Callouts 

  • 相关阅读:
    Golang 单例模式 singleton pattern
    golang可见性规则(公有与私有,访问权限)
    golang init方法和main方法初始化顺序
    Golang的面向对象编程【结构体、方法、继承、接口】
    Convert Sorted List to Binary Search Tree——将链表转换为平衡二叉搜索树 &&convert-sorted-array-to-binary-search-tree——将数列转换为bst
    C/C++程序到内存分配(转)
    有关C/C++指针的经典面试题(转)
    C结构体之位域(位段)(转)
    Balanced Binary Tree——数是否是平衡,即任意节点左右字数高度差不超过1
    Path SumI、II——给出一个数,从根到子的和等于它
  • 原文地址:https://www.cnblogs.com/mingmingruyuedlut/p/3512262.html
Copyright © 2011-2022 走看看