简体   繁体   English

Salesforce PHP SOAP API-无法使自定义WebService工作

[英]Salesforce PHP SOAP API - Unable to get custom WebService working

Let me set the scene: 让我设置场景:

I'm a PHP developer that needs to take info from a web form and send it into a clients Salesforce. 我是一名PHP开发人员,需要从Web表单获取信息并将其发送到客户Salesforce。 At first I though it was as simple as using Web2Lead. 起初我虽然很简单,但是使用Web2Lead一样简单。 However the client has a Salesforce developer in house. 但是,客户内部有一个Salesforce开发人员。

The in house developer has sent me partner.wsdl and CatalystWebservice.wsdl files along with login details to their sandbox to run all this on. 内部开发人员已向我发送了partner.wsdlCatalystWebservice.wsdl文件以及登录详细信息到他们的沙箱,以运行所有这些信息。 The in house developer has basically said I need to use the SOAP API of Salesforce and once connected and logged in I need to call ->makeContact("FormField1", "FormField2", "etc..."); 内部开发人员基本上已经说过,我需要使用Salesforce的SOAP API,并且一旦连接并登录,我需要调用->makeContact("FormField1", "FormField2", "etc...");

So after spending all day trying many things and hitting many problems I have finally hit a wall I cannot climb. 因此,在花了一整天的时间尝试许多事情并遇到许多问题之后,我终于碰壁了,我无法攀登。 Here is my PHP code I have now: 这是我现在拥有的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>

I have starred out sensitive information for here. 我已经为这里加注了敏感信息。 When I run the above code I get the following output: 当我运行上面的代码时,我得到以下输出:

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
.....

And the CatalystWebservice.wsdl.xml file 还有CatalystWebservice.wsdl.xml文件

The in house developer has developed something in C# to test his WebService and it works perfectly fine so it must be something I am not doing right. 内部开发人员已经用C#开发了一些东西来测试他的WebService,并且效果很好,所以一定是我做错了。 What am I doing incorrectly? 我做错了什么?

I found the solution... I had to make sure I was sending the data as an associative array like so: 我找到了解决方案...我必须确保我将数据作为关联数组发送,如下所示:

$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" ),
                    )
                );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM