PHP EWS订阅响应错误编码对象没有属性

时间:2018-01-26 13:43:10

标签: php soap wsdl php-ews

我正在使用garethp/php-ews库来下载推送到我脚本的新电子邮件(通过推送通知)。作为推送通知的一部分,我需要以“OK”状态响应;我在下面尝试抛出一个SOAP-Error:

  

PHP致命错误:SOAP-ERROR:编码:对象没有   'SubscriptionStatus'属性在......

<?php

ini_set("soap.wsdl_cache_enabled", 0);
require_once('vendor/autoload.php');

use garethp\ews\API;
use garethp\ews\API\ExchangeWebServicesAuth;
use garethp\ews\API\Type\ConnectingSIDType;
use garethp\ews\API\Type\ExchangeImpersonation;
use garethp\ews\API\Type\ItemIdType;
use garethp\ews\API\Type\NonEmptyArrayOfBaseItemIdsType;
use garethp\ews\API\Type\ItemResponseShapeType;
use garethp\ews\API\Message\SendNotificationResultType;
use garethp\ews\API\Message\SendNotificationResult;
use garethp\ews\API\Message\ArrayOfResponseMessagesType;
use garethp\ews\API\Message\SendNotificationResponseType;
use garethp\ews\API\Message\GetItemType;
use garethp\ews\API\Enumeration\DefaultShapeNamesType;
use garethp\ews\API\Enumeration\SubscriptionStatusType;

class EwsPushService
{
    public function SendNotification($arg)
    {
        $responseCode = $arg->ResponseMessages->SendNotificationResponseMessage->ResponseCode;
        if ($responseCode == "NoError") {
            $notification = $arg->ResponseMessages->SendNotificationResponseMessage->Notification;
            if (isset($notification->NewMailEvent)) {
                // Download message
            }
        }

        $notificationResponse = new SendNotificationResultType();
        $notificationResponse->setSubscriptionStatus(SubscriptionStatusType::OK);

        return $notificationResponse;
    }
}

$service = new EwsPushService();
$server = new SoapServer('php-ews/wsdl/NotificationService.wsdl');
$server->setObject($service);
$server->handle();

我试图删除缓存的WSDL文件,并在我的脚本中将soap.wsdl_cache_enabled设置为0而没有任何运气。我正在使用的WSDL来自nginn-exchange,并添加了一些:

<wsdl:service name="NotificationServices">
    <wsdl:port name="NotificationServicePort" binding="tns:NotificationServiceBinding">
        <soap:address location="" />
    </wsdl:port> 
</wsdl:service>

我不确定出现了什么问题,或者是查看SOAP问题的最佳方式,但我们将非常感谢任何建议。

[编辑] 我相信问题实际上是我正在使用的库;所以我已经提出an issue并在我确定知道时会更新...

1 个答案:

答案 0 :(得分:0)

该库符合PSR-2代码样式,因此订阅状态存储在名为$subscriptionStatus的变量中,通常由toXmlObject传递给ucfirstType类中调用,这在我的案例中没有发生。要解决这个问题,我需要像这样调用toXmlObject

$notificationResponse = new SendNotificationResultType();
$notificationResponse->setSubscriptionStatus(SubscriptionStatusType::OK);
return $notificationResponse->toXmlObject();