Salesforce PHP SOAP API - 无法使自定义Web服务正常工作

时间:2012-02-24 16:56:21

标签: php api soap salesforce

让我设置场景:

我是一名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", "****", "no-one@****", "0123456789", "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 个答案:

答案 0 :(得分: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" ),
                    )
                );
相关问题