使用PHP的EWS推送订阅

时间:2014-08-20 11:22:34

标签: php web-services soap exchangewebservices

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

我已经启动了EWS Push Subscription,但是当EWS向我的服务发送SOAP通知时,似乎无法发送正确的SOAP响应(为了使订阅保持活动状态)。

this页面开始,我的印象是我的SOAP响应应该如下:

<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似乎并不接受我的回复是有效的。

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

使用带有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 library可能会有所帮助。

非常感谢任何帮助。

我还发布了一个更具体的问题here,但没有回复,所以我想问一个人是否真的使用任何方法实现了这个问题。

1 个答案:

答案 0 :(得分:3)

似乎我很接近,但在实例化SoapServer类时需要包含NotificationService.wsdl。然后,WSDL允许SoapServer类相应地格式化响应。

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

WSDL未包含在php-ews库下载中,但它包含在Exchange Server安装中。如果像我这样您无法访问Exchange Server安装,则可以找到文件here。我还必须将以下内容添加到WSDL的末尾,因为我在本地存储WSDL而不是使用自动发现:

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

所以完整的PHP代码如下:

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>

希望能帮助别人,因为这花了我一段时间才弄清楚!

相关问题