0

I just downloaded PHP-EWS, installed following the README instructions, and spun up a script to test out its functionalities. When I try running the script in my browser, I get the following message: enter image description here

I get the same message when I supply a login I know is invalid. It seems I am connecting to my Exchange server, but it's not recognizing the credentials I provide.

Here is the script I am using

<?php
function __autoload($className)
{
    $className = str_replace('_','/', $className);
    $sFileName = $className . '.php';

    if (file_exists($sFileName) && !class_exists($className))
    {
        require_once $sFileName;
    }
    // If the above if fails, you're program will terminate, there is no way to catch this.
}

include("ExchangeWebServices.php");

$host = "https://myexchange/EWS/Services.wsdl";
$username = "myusername@mydomain.com";
$password = "mypassword";

$ews = new ExchangeWebServices($host, $username, $password);

$request = new EWSType_FindItemType();

$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::DEFAULT_PROPERTIES;

$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;

$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX;

// sort order
$request->SortOrder = new EWSType_NonEmptyArrayOfFieldOrdersType();
$request->SortOrder->FieldOrder = array();
$order = new EWSType_FieldOrderType();
// sorts mails so that oldest appear first
// more field uri definitions can be found from types.xsd (look for UnindexedFieldURIType)
$order->FieldURI->FieldURI = 'item:DateTimeReceived'; 
$order->Order = 'Ascending'; 
$request->SortOrder->FieldOrder[] = $order;

$response = $ews->FindItem($request);
echo '<pre>'.print_r($response, true).'</pre>';

?>
Lloyd Banks
  • 35,740
  • 58
  • 156
  • 248

1 Answers1

2

Try testing your access by:

Hitting the server url directly: https://YOUREXCHANGESERVER/EWS/Services.wsdl

You should be prompted for credentials. After you enter your credentials you will be presented with the WSDL definition. If it does not present you a WSDL definition that looks like the example below then check with your administrator on credentials or if there are any firewall blocks put in place.

Example (Partial response):

<wsdl:definitions targetNamespace="http://schemas.microsoft.com/exchange/services /2006/messages"><wsdl:types><xs:schema><xs:import namespace="http://schemas.microsoft.com/exchange/services/2006/messages" schemaLocation="messages.xsd"/></xs:schema></wsdl:types>

A great tool I use in analyzing web services is: SOAP-UI by SmartBear