2012-02-24 43 views
0

讓我設置場景:Salesforce的PHP SOAP API - 無法獲取定製的WebService工作

我是一個PHP開發人員,需要從一個Web表單需要的信息,並將其發送到客戶的Salesforce。起初,我認爲它和使用Web2Lead一樣簡單。然而,客戶有一位Salesforce開發人員。

內部開發者已將我的partner.wsdlCatalystWebservice.wsdl文件以及登錄詳細信息發送到他們的沙箱以運行所有這些。內部開發人員基本上說我需要使用Salesforce的SOAP API,並且一旦連接並登錄,我需要撥打->makeContact("FormField1", "FormField2", "etc...");

因此,花了一整天的時間嘗試很多事情並遇到許多問題後,我終於撞到了牆上不能爬。這裏是我現在使用的PHP代碼:

<pre> 
<?php 
define("SOAP_CLIENT_BASEDIR", "../soapclient"); 
$USERNAME = '******@********' ; 
$PASSWORD = '******************************' ; 
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php'); 
require_once (SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php'); 

try { 

    $mySforceConnection = new SforcePartnerClient(); 
    $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner2.wsdl.xml'); 
    $loginResult = $mySforceConnection->login($USERNAME, $PASSWORD); 

    $location = $mySforceConnection->getLocation(); 
    $session_ID = $mySforceConnection->getSessionId(); 

    $client = new SoapClient(SOAP_CLIENT_BASEDIR.'/CatalystWebservice.wsdl.xml'); 
    $sforce_header = new SoapHeader("http://soap.sforce.com/schemas/class/CatalystWebservice", "SessionHeader", array("sessionId" => $session_ID)); 
    $client->__setSoapHeaders(array($sforce_header)); 

    $client->makeContact("*****", "*****", "Address1", "Address2", "London", "****", "[email protected]****", "", "07891236456", "New Build Homebuy", "This is my question\n\nAnd an other line", "1", "Test"); 

} catch (Exception $e) { 
    print_r($e); 
} 
?> 
</pre> 

我已經爲此列出了敏感信息。當我運行上面的代碼中,我得到以下輸出:

SoapFault Object 
(
    [message:protected] => UNKNOWN_EXCEPTION: An unexpected error occurred. Please include this ErrorId if you contact support: ***********-*** (***********) 
    [string:Exception:private] => 
    [code:protected] => 0 
    [file:protected] => /home/******/public_html/********/test/partner.php 
    [line:protected] => 23 
    [trace:Exception:private] => Array 
     (
      [0] => Array 
..... 

而且CatalystWebservice.wsdl.xml file

將在內部開發人員已經開發出在C#中的東西,以測試他的WebService和它的作品完美的罰款,因此必須有一些我我做得不對。我做錯了什麼?

+1

有沒有什麼辦法可以包括它的生成和發送XML的轉儲,與C#版本相比? (例如,使用像Fiddler這樣的本地代理)這會讓你知道從哪裏開始尋找。 – 2012-02-24 18:29:29

+0

另一件需要檢查的是你是否傳入了安全令牌(附加到密碼中) - 如果沒有,你也需要這樣做。 – 2012-02-25 02:44:12

+0

我可能會先使用嗅探器來捕獲您生成的XML並將其與開發人員進行比較。你得到的錯誤是來自SFDC的「錯誤的錯誤」 - 通常是一個平臺級別的未處理的異常 - 在這種情況下,可能確實意味着某些東西相當混亂,比如不符合的XML,錯誤的編碼等。 – jkraybill 2012-02-26 22:54:31

回答

1

我找到了解決辦法...我必須確保我發送數據作爲關聯數組,像這樣:

$response = $client->makeContact 
       (
        array 
        (
         "sLastName" => (string) $wpcf7_data->posted_data['last-name'], 
         "sFirstName" => (string) $wpcf7_data->posted_data['first-name'], 
         "sAddress1" => (string) $wpcf7_data->posted_data['address-one'], 
         "sAddress2" => (string) $wpcf7_data->posted_data['address-two'], 
         "sCity" => (string) $wpcf7_data->posted_data['town-city'], 
         "sPostcode" => (string) $wpcf7_data->posted_data['post-code'], 
         "sEmail" => (string) $wpcf7_data->posted_data['email-address'], 
         "sPhone" => (string) $wpcf7_data->posted_data['telephone'], 
         "sMobile" => (string) "", 
         "sEnquiries" => (string) $wpcf7_data->posted_data['enquiry'], 
         "sComment" => (string) $wpcf7_data->posted_data['comments'], 
         "sPropertyID" => (string) wpcf7_special_mail_tag_for_post_data("", "_post_id"), 
         "sPropertyName" => (string) wpcf7_special_mail_tag_for_post_data("", "_post_title"), 
        ) 
       );