使用PHP的EWS推送订阅 [英] EWS Push Subscription using PHP

查看:130
本文介绍了使用PHP的EWS推送订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何使用PHP响应EWS(Exchange Web服务)推送通知.

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

我已经启动 EWS推送订阅,但是当EWS向我的服务发送SOAP通知时,似乎无法发送正确的SOAP响应(以保持订阅有效).

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.

来自页,我的印象是我的SOAP响应应该如下:

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>

但是,EWS似乎并没有接受我的回应为有效.

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

我尝试了以下2个代码段,但没有运气:

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

使用带有Content-Type标头的SOAP字符串进行响应

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>';

或使用SOAP服务进行响应

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

知道我在代码中使用的类可能来自 PHP-EWS库,这可能会有所帮助.

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

任何帮助将不胜感激.

我还在此处发布了一个更具体的问题,但没有任何回应,因此我想问一问是否有人真的可以使用任何方法来完成这项工作.

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.

推荐答案

似乎我很亲密,但是在实例化SoapServer类时需要包括NotificationService.wsdl.然后,WSDL允许SoapServer类相应地格式化响应.

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(

WSDL未包含在php-ews库下载中,但已包含在Exchange Server安装中.如果像我一样,您无权访问Exchange Server安装,则可以找到文件

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>

因此,完整的PHP代码如下:

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

哪个给出以下输出:

<?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!

这篇关于使用PHP的EWS推送订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆