【问题标题】:Salesforce PHP SOAP API - Unable to get custom WebService workingSalesforce PHP SOAP API - 无法让自定义 WebService 工作
【发布时间】:2012-02-24 16:56:21
【问题描述】:

让我来设置场景:

我是一名 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,它工作得非常好,所以它一定是我做的不对。我做错了什么?

【问题讨论】:

  • 与 C# 版本相比,有什么方法可以包含它生成和发送的 XML 的转储? (例如,使用像 Fiddler 这样的本地代理)这会让您知道从哪里开始查找。
  • 要检查的另一件事是您是否传递了安全令牌(附加到密码) - 如果没有,您也需要它。
  • 我可能会首先使用嗅探器来捕获您生成的 XML 并将其与开发人员的进行比较。您收到的错误是来自 SFDC 的“错误错误”——通常是平台级未处理的异常——在这种情况下,这可能确实意味着某些事情相当混乱,例如不符合标准的 XML、错误编码等。
  • 巧合的是,我今天早些时候发布了一个从 PHP 转储原始 SOAP 请求和响应的示例 - gist.github.com/1926321 - 这可能会帮助您调试它。
  • 我使用 Java API,所以我不确定它们有多相似。我知道我在推送我认为完全有效的数据时遇到了一些问题。事实证明,您需要按原样填充数据类型,而不是字符串等值。因此,如果您需要设置日期时间,则按原样推送 datetime 对象,而不是该日期/时间的字符串表示形式......等更新包含双精度值的字段,将值作为双精度推送不是字符串,甚至不是浮点数。我知道 PHP 通常不是一种强类型语言,所以我不知道这将如何反映您当前的问题。 :)

标签: php api soap salesforce


【解决方案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" ),
                    )
                );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多