75858

EWS Push Subscription using PHP

Question:

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

I have initiated the <a href="http://msdn.microsoft.com/en-us/library/office/aa566188%28v=exchg.140%29.aspx#sectionSection3" rel="nofollow">EWS Push Subscription</a> 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 <a href="http://www.thesoftwaregorilla.com/2010/04/exchange-web-services-subscriptions-and-notifications/" rel="nofollow">this</a> 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:

<strong>Respond using a SOAP string with Content-Type header</strong>

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

<strong>OR Respond using a SOAP service</strong>

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 <a href="https://github.com/jamesiarmes/php-ews" rel="nofollow">PHP-EWS library</a>.

Any help would be greatly appreciated.

I also posted a more specific question <a href="https://stackoverflow.com/q/25392228/799588" rel="nofollow">here</a>, but have had no responses so thought I would ask whether someone has actually gotten this working using any method.

Answer1:

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 <a href="https://code.google.com/p/nginn-exchange/source/browse/trunk/ExchangeIntegration.Service/EWS/NotificationService.wsdl?r=2" rel="nofollow">here</a>. 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!

Recommend

  • Why won't polymer's flex attribute/class just work?
  • Dynamic Sieve Algorithms for Prime Generation
  • Is it possible to add a text overlay to videos?
  • RFX equivalent data type for _int64 in Informix
  • How to replace one set of color 'shades' with another set
  • Camel REST Bean Chaining
  • Problem with sockets in C#
  • Condor job using DAG with some jobs needing to run the same host
  • How to read data from a text file if the file location is not known in c#?
  • View/Download Pdf Files in React - Router 4
  • Index.php as custom error page
  • powershell Get-Counter -ComputerName parameter on Windows 7
  • Xamarin MonoAndroid Azure mobile service InsertAsync
  • Private IP address in reserved subnet range
  • How To Customize ASP.NET Chart Databound To SqlDataSource
  • Unexpected token ILLEGAL while running node.js mocha test
  • Execute scripts AJAX returns
  • Unable to decode certificate at client new X509Certificate2()
  • Display images in Django
  • Word Open XML Mail Merge
  • DotNetZip - Calculate final zip size before calling Save(stream)
  • Is there a amazon webstore API for customers?
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • Release, debug version and Authorization Google?
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • AT Commands to Send SMS not working in Windows 8.1
  • Is there a mandatory requirement to switch app.yaml?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Acquiring multiple attributes from .xml file in c#
  • Free memory of cv::Mat loaded using FileStorage API
  • How do I configure my settings file to work with unit tests?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • apache spark aggregate function using min value
  • How can I remove ASP.NET Designer.cs files?
  • Sorting a 2D array using the second column C++
  • Binding checkboxes to object values in AngularJs
  • java string with new operator and a literal