dscs63759 2014-08-20 11:22
浏览 94
已采纳

使用PHP的EWS推送订阅

Does anyone know how to respond to EWS (Exchange Web Services) Push Notifications using PHP.

I have initiated the EWS Push Subscription but cannot seem to send the correct SOAP response (in order to keep the subscription alive) when EWS sends my service a SOAP notification.

Taken from this page, I was under the impression that my SOAP response should be as follows:

<s:Envelope xmlns:s= "http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <SendNotificationResult xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
            <SubscriptionStatus>OK</SubscriptionStatus>
        </SendNotificationResult>
    </s:Body>
</s:Envelope>

However, EWS doesn't seem to be accepting my response as valid.

I have tried the following 2 code snippets with no luck:

Respond using a SOAP string with Content-Type header

header( 'Content-Type: text/xml; charset=utf-8' );

echo '<?xml version="1.0" encoding="utf-8"?>'.
'<s:Envelope xmlns:s= "http://schemas.xmlsoap.org/soap/envelope/">'.
    '<s:Body>'.
        '<SendNotificationResult xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">'.
            '<SubscriptionStatus>OK</SubscriptionStatus>'.
        '</SendNotificationResult>'.
    '</s:Body>'.
'</s:Envelope>';

OR Respond using a SOAP service

class ewsService {
    public function SendNotification( $arg ) {
        $result = new EWSType_SendNotificationResultType();
        $result->SubscriptionStatus = 'OK';
        return $result;
    }
}

$server = new SoapServer( null, array(
    'uri' => $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'],
));
$server->setObject( new ewsService() );
$server->handle();

It might help to know that the classes I am using in my code come from the PHP-EWS library.

Any help would be greatly appreciated.

I also posted a more specific question here, but have had no responses so thought I would ask whether someone has actually gotten this working using any method.

  • 写回答

1条回答 默认 最新

  • douci1851 2014-08-21 09:02
    关注

    It would seem that I was close but needed to include the NotificationService.wsdl when instantiating the SoapServer class. The WSDL then allows that SoapServer class to format the response accordingly.

    $server = new SoapServer( PHPEWS_PATH.'/wsdl/NotificationService.wsdl', array(
    

    The WSDL was not included in the php-ews library download, however it is included with the Exchange Server installation. If like me you don't have access to the Exchange Server installation you can find the file here. I also had to add the following to the end of the WSDL because I was storing the WSDLs locally and not using autodiscovery:

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

    So the full working PHP code is as follows:

    class ewsService {
        public function SendNotification( $arg ) {
            $result = new EWSType_SendNotificationResultType();
            $result->SubscriptionStatus = 'OK';
            //$result->SubscriptionStatus = 'Unsubscribe';
            return $result;
      }
    }
    
    $server = new SoapServer( PHPEWS_PATH.'/wsdl/NotificationService.wsdl', array(
        'uri' => $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'],
    ));
    $server->setObject( $service = new ewsService() );
    $server->handle();
    

    Which gives the following output:

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/messages">
        <SOAP-ENV:Body>
            <ns1:SendNotificationResult>
                <ns1:SubscriptionStatus>OK</ns1:SubscriptionStatus>
            </ns1:SendNotificationResult>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    

    Hope that helps someone else because that took me a while to figure out!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题