【问题标题】:EWS Push Subscription using PHP使用 PHP 的 EWS 推送订阅
【发布时间】:2014-10-13 17:38:41
【问题描述】:

有谁知道如何使用 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 个代码 sn-ps,但没有成功:

使用带有 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,但没有得到任何回复,所以我想问一下是否有人真的用任何方法让它工作了。

【问题讨论】:

  • 你知道传入的推送消息记录在哪里吗?
  • @simbabque 这是很久以前的事了,不记得了。你必须用谷歌搜索它,但他们为 365 实现了 REST API,我不会再为 SOAP 实现而烦恼了。如果您无法支持旧版本,那很遗憾。

标签: php web-services soap exchangewebservices


【解决方案1】:

似乎我很接近,但在实例化 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>

希望对其他人有所帮助,因为我花了一段时间才弄清楚!

【讨论】:

  • 在您的示例中,SOAP 如何在没有登录参数的情况下与 Exchange 对话?
猜你喜欢
  • 1970-01-01
  • 2015-09-14
  • 1970-01-01
  • 2014-03-05
  • 2016-01-20
  • 2019-01-11
  • 2012-04-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多