5

I've never tried this before but I'm trying to use PHP to get data about an exchange account (for example the number of emails in the Inbox and the amount of unread email in the inbox). Just for the record, the PHP server is on a different domain than the exchange server.

My PHP server is running on:
- System: Linux
- PHP Version 5.3.3
- cURL Information 7.19.7
- cURL NTLM Yes
- Soap Client and server enabled

The Excahnge is running:
- Version 14.1 or Exchange 2010 SP1

I have tried 3 PHP libraries that all return a very similar error. The Heartspring Exchange Web Services for PHP, PHP-EWS and EWSWrapper libraries.

As all 3 libraries require, I downloaded the three files from the exchange server and placed them in the appropriate location on the PHP server web directory:
- Services.wsdl (used both uppercase and lovercase first letter)
- messages.xsd
- types.xsd

I also added the ExchangeServiceBinding to Services.wsdl and pointed the soap:address location to the exchange servers Exchange.asmx (I tested the link and it´s correct).

I get a very similar error message with all 3 libraries, here is the full error from EWSWrapper:

    Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: 
    Parsing Schema: can't import schema from 
    '/var/www/vhosts/domain.com/EWSWrapper/wsdl/types.xsd'in 
    /var/www/vhosts/domain.com/EWSWrapper/NTLMSoapClient/Exchange.php:52 
    Stack trace: #0 
    /var/www/vhosts/domain.com/EWSWrapper/NTLMSoapClient/Exchange.php(52):
    SoapClient->SoapClient('/var/www/vhosts...', Array) 
    #1 
    /var/www/vhosts/domain.com/EWSWrapper/ExchangeWebServices.php(483): 
    NTLMSoapClient_Exchange->__construct('/var/www/vhosts...', Array) 
    #2 
    /var/www/vhosts/domain.com/EWSWrapper/ExchangeWebServices.php(235): 
    ExchangeWebServices->initializeSoapClient() 
    #3 
    /var/www/vhosts/domain.com/EWSWrapper/EWSWrapper.php(529): 
    ExchangeWebServices->FindFolder(Object(EWSType_FindFolderType)) 
    #4 
    /var/www/vhosts/domain.com/EWSWrapper/test in
    /var/www/vhosts/domain.com/EWSWrapper/NTLMSoapClient/Exchange.php on line 52

The Exchange.php:52 points to:

parent::__construct($wsdl, $options);

The ExchangeWebServices.php(483) points to:

protected function initializeSoapClient() {
        return new NTLMSoapClient_Exchange(
            dirname(__FILE__).'/wsdl/services.wsdl',
            array(
                'user' => $this->username,
                'password' => $this->password,
                'location' => 'https://'.$this->server.'/EWS/Exchange.asmx',
            )); // end return
    } // end function initializeSoapClient()

There I tried having the server path (/var/www/...) and also the web url path (http://domain.com/...) to the services.wsdl and also the server location, that changes nothing exept for the urls in the error code above.

The ExcahngeWebServices.php(235) point to:

public function FindFolder($request) {
        $request->getAsSOAP();
        return $this->initializeSoapClient()->{__FUNCTION__}($request);
    } // end function FindFolder()

It´s seems that there might be an issue with the $request, as the next trace EWSWrapper.php(529) point to:

// make the actual call
        $response = $this->ews->FindFolder($request);

        return $response;

Any help would be appreciated as an extensive Google and Stack Exchange search has not helped. I would think that the path to the types.xsd is wrong or something wrong with the $request.

8
  • Just noticed one thing, I downloaded a local copy of Services.wsdl and added the exchange server SOAP address binding. When I now navigate to that address (domain.com/EWS/Exchange.asmx) it returns me to the excahnge Services.wsdl (domain.com/EWS/Services.wsdl) that does not have the soap address binding. Does that make any difference? Do I need to update the services.wsdl file on the excahnge server? Dec 18, 2012 at 16:45
  • I got this working with php 5.3 once using PHP's SoapClient. I also had to download and modify the exchange wsdl. When will the error be thrown? on __construct()?
    – hek2mgl
    Dec 18, 2012 at 17:08
  • All your steps looking ok to me. Maybe there are problems with permissions? Have you checked the output of var_dump(is_readable('dirname(__FILE__).'/wsdl/types.xsd')); ? (from relevant content)
    – hek2mgl
    Dec 18, 2012 at 17:31
  • @ hek2mgl - the 'var_dump' returns 'bool(true)'. I´m going to trace the '__construct()' this evening. Dec 18, 2012 at 21:27
  • @ hek2mgl - yes, it seems that the error is in all cases thrown in the 'SoapClient constructor'. Either on the soapclient $wsdl or $options. Dec 19, 2012 at 1:15

2 Answers 2

0

This example uses the PHP internal class SoapClient to display the subjects of Microsoft Exchange 2010 calendar items. To get it working you will have to download and modify 'services.wsdl', 'types.xsd', 'messages.xsd' as the questioner mentioned. The files are expected to reside in the same folder as the php file.

<?php

ini_set('display_errors', '1'); // for debugging
$server = "192.168.0.23";
$wsdl = "file:///" . dirname(__FILE__) . "/services.wsdl";

// valid login credentials
$options = array (
    'login' => '[email protected]',
    'password' => 'secret'
);

$client = new SoapClient($wsdl, $options);
printf("Connected to %s%s", $server, PHP_EOL);

$FindItem->Traversal = "Shallow";
$FindItem->ItemShape->BaseShape = "AllProperties";
$FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar";
$FindItem->CalendarView->StartDate = "2012-08-01T00:00:00Z";
$FindItem->CalendarView->EndDate = "2012-08-31T00:00:00Z";
$result = $client->FindItem($FindItem);
$calendaritems = $result
  ->ResponseMessages
  ->FindItemResponseMessage
  ->RootFolder
  ->Items
  ->CalendarItem;

foreach($calendaritems as $item) { 
    printf("%s%s", $item["Subject"], PHP_EOL);
}

You will find important information about using EWS with PHP in this tutorial

1
  • Thanks hek2mgl - Although I´m still getting the same error with the above code you provided. Dec 19, 2012 at 1:17
0

I traced the problem to a possible Bug in PHP or a possible solution for some users that are not effected by the bug:

  1. Bug #61463: cant import schema when using https soapservice

  2. Storing services.wsdl, types.xsd and messages.xsd locally but referring the schema import in services.wsdl to the exchange servers messages.xsd and also in messages.xsd referring the schema import to the exchange servers types.xsd (instead of the locally stored ones that for some reason can not be imported in my case).

After that I no longer get the Parsing Schema: can't import schema from error with at least the code provided in Talking SOAP With Exchange.

I´m actually still getting the schema import error on the posted server in the original post. But NOT on another test server running PHP 5.2.7. I´m guessing that the PHP BUG is not effecting that test server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.