使用SOAP和PHP,简单的问题


Using SOAP with PHP, simple issue

我正在尝试将API集成到我的站点中(API并不重要,问题在于SOAP)。我通常不使用PHP编写代码,而是专注于javascript,所以SOAP和相关的东西对我来说很陌生。我已经搜索和尝试了大约2个半小时的不同东西,并设法缩小了我的问题。

我调用了$client->__getFunctions(),它给了我一个字符串列表,定义了我能够使用的所有函数。这是我想使用的函数字符串:

"GetActivationCodeResponse GetActivationCode(GetActivationCode $parameters)"

我已经和API的创建者按照惯例进行了写作,因为这是我第一次使用SOAP,也是一段时间以来第一次使用php。

所以我在我的类中创建了一个名为GetActivationCode的函数,它看起来像这样:

public function GetActivationCode($params) {
    $this->client->GetActivationCode($params);
    var_dump($this->client);
}

这将始终输出SOAP错误:

Server was unable to process request. --->
System.NullReferenceException:  
Object reference not set to an instance of an object

所以我猜测它希望传递的参数是一个名为GetActivationCode的类的实例?我不知道如何做到这一点,也不想创建一个全新的类来服务于一个函数(但如果这是解决方案,我会的)。

I级已编写

<?php
require_once("../includes/mbApi.php");
error_reporting(E_ALL);
ini_set('display_errors', '1');
class MBActivateService extends MBAPIService 
{
    function __construct($debug = false)
    {
        $serviceUrl = "http://" . GetApiHostname() . "/0_5/SiteService.asmx?wsdl";
        $this->debug = $debug;
        $option = array();
        if ($debug)
        {
            $option = array('trace'=>1);
        }
        $this->client = new soapclient($serviceUrl, $option);
    }
    public function GetActivationCode($s, $k, $ids) {
        var_dump($this->client->__getFunctions());
        $arr = array();
        $arr["SourceName"] = $s;
        $arr["Password"] = $k;
        $arr["SiteIDs"] = $ids;
        var_dump($arr);
        $this->client->GetActivationCode($arr);
    }
}
$activate = new MBActivateService();
$result = $activate->GetActivationCode("She3", "private api key", array("28856"));
var_dump($result);
?>

总体目标

这是总体目标,以防有人能提供更好的解决方案。我需要发送以下SOAP请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://clients.mindbodyonline.com/api/0_5">
   <soapenv:Header/>
   <soapenv:Body>
      <GetActivationCode>
         <Request>
            <SourceCredentials>
               <SourceName>XXXX</SourceName>
               <Password>XXXX</Password>
               <SiteIDs>
                  <int>XXXX</int>
               </SiteIDs>
            </SourceCredentials>
         </Request>
      </GetActivationCode>
   </soapenv:Body>
</soapenv:Envelope>

我需要发送SourceNamePasswordSiteIDs(数组)的选项。

提前感谢您的任何意见!

这听起来很熟悉。我会尝试的第一件事是将你的函数重写为:
public function GetActivationCode($params) {
    var_dump($this->client->GetActivationCode(array(
        'Request' => array(
            'SourceCredentials' => $params
        ),
    )));
}

此外,为了调试,您可以将其添加到SoapClient构造函数的选项中:

array(
    'trace' => true,
)

通过这种方式,您可以执行$this->client->__getLastRequest()来调试代码。