如何在Salesforce中建立Web Service供外部系統調用

來源:互聯網
上載者:User

在Salesforce中可以建立Web Service供外部系統調用,並且可以以SOAP或者REST方式向外提供調用介面,接下來的內容將詳細講述一下用SOAP的方式建立Web Service並且用Asp.net的程式進行簡單的調用。

1):在Salesforce中建立如下Class

【註:要想使其成為web service,那麼class一定要定義成global的,具體的方法要用 webService static 修飾】

【代碼中省略了GenerateAccountFromXmlInfo方法的具體實現,細節請看:http://www.cnblogs.com/mingmingruyuedlut/p/3497646.html 】

global class SFAccountWebService {            webService static string UpsertAccount(String accountXmlInfo) {        Account currentAcc = GenerateAccountFromXmlInfo(accountXmlInfo);        try        {            Account acc = [Select Id From Account a Where AccountNumber =: currentAcc.AccountNumber];            if(acc != null){                currentAcc.Id = acc.Id;            }            upsert currentAcc;            return 'true';        }        catch(exception ex){            return 'false';            }    }                    private static Account GenerateAccountFromXmlInfo(String accountXmlInfo){        Account currentAcc = new Account();        // Parse the xml info to generate the Account Object        return currentAcc;    }        }

2):在儲存好上述的class之後,我們到setup --> build --> develop --> apex classes 中找到剛剛儲存的class,我們會發現在對應的Action中有WSDL這個選項,此選項就是Salesforce預設所提供的將Web Service的class轉化成WSDL檔案。如下圖所示

3):點擊上圖的WSDL按鈕,會看到如下介面,這裡顯示的是產生的WSDL檔案的詳細資料,我們點擊滑鼠右鍵,將此檔案儲存到本地,這裡姑且取名為SFAccountWebService.wsdl

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.