Search code examples
phpsoapwsdlphp-ews

PHP EWS Subscription Response error encoding object has no property


I'm using the garethp/php-ews library to download new email messages which are pushed to my script (via Push Notifications). As part of the push notifications I need to respond with an "OK" status; my attempt below is throwing a SOAP-Error:

PHP Fatal error: SOAP-ERROR: Encoding: object has no 'SubscriptionStatus' property in ...

<?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();

I've attempted to remove the cached WSDL files, and have set soap.wsdl_cache_enabled to 0 in my script without any luck. The WSDL I'm using is from nginn-exchange with a minor addition of:

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

I'm not sure what's going wrong, or the best way to look into SOAP issues, but any suggestions would be greatly appreciated.

[Edit] I believe the issue is actually with the library I'm using; so I've raised an issue and will update when I know for sure...


Solution

  • The library complies with the PSR-2 code style, so the subscription status is stored in a variable called $subscriptionStatus, normally this would be passed to ucfirst as a result of the toXmlObject call within the Type class, which was not happening in my case. To resolve this I needed to call toXmlObject like so:

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