Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All examples render an error "The specified server version is invalid" #44

Closed
marvelade opened this issue Jun 8, 2016 · 9 comments
Closed

Comments

@marvelade
Copy link

After some struggle and online research I managed to get the autoloading correct by using Composer, so no more "Class not found" errors.

After this first success, I wanted to try some of the examples (examples/basic/quickstart.php seemed like a good starting point), so I add this at the top to make the autoloading happen:

require_once "../../vendor/autoload.php";

after which my browser takes quite a long time to reload the page (so I guess something is happening in communicating to the Exchange server?) only to give me a 500 Error.

/var/log/apache2/error.log tells me that SOAP thinks "The specified server version is invalid":

PHP Fatal error:  Uncaught SoapFault exception: [soap:Client] The specified server version is invalid. in /var/www/html/php-ews-master/src/API/NTLMSoapClient.php:127
Stack trace:

#0 /var/www/html/php-ews-master/src/API/NTLMSoapClient.php(127): SoapClient->__call('GetFolder', Array)

#1 /var/www/html/php-ews-master/src/API/ExchangeWebServices.php(294): garethp\\ews\\API\\NTLMSoapClient->__call('GetFolder', Array)

#2 /var/www/html/php-ews-master/src/API.php(295): garethp\\ews\\API\\ExchangeWebServices->__call('GetFolder', Array)

#3 /var/www/html/php-ews-master/src/API.php(295): garethp\\ews\\API\\ExchangeWebServices->GetFolder(Object(garethp\\ews\\API\\Type))

#4 /var/www/html/php-ews-master/src/API.php(313): garethp\\ews\\API->getFolder(Array)

#5 /var/www/html/php-ews-master/examples/basic/quickstart.php(20): garethp\\ews\\API->getFolderByDistinguishedId('calendar')

#6 {main}


thrown in /var/www/html/php-ews-master/src/API/NTLMSoapClient.php on line 127

I altered the call to API::withUsernameAndPassword() with my domain credentials of course.

When I google "The specified server version is invalid" I get quite a few results that all have to do with Windows development (.NET, C#, VBA, PowerShell) failing to connect to an Exchange environment.

The documentation states under "Usage" that the server version "Defaults to Exchange 2007".

However if I do this:

require_once "../../vendor/autoload.php";

/**
 * Quick Start
 *
 * This file is an example of how to quickly create a Calendar Item without going through the CalendarAPI, to show
 * that you can create items directly
 */

//Include the API
use garethp\ews\API;
use garethp\ews\API\Enumeration;

//Create and build the client
$api = API::withUsernameAndPassword('EXCHANGESERVER', 'DOMAIN\\MYUSERNAME', 'PASSWORDIMNOTTELLINGYOU');
print_r($api);
die();

I get a mapping of an object of type "garethp\ews\API". In that text dump, when I do a find on the string "version", I find the following 2 properties set to "Exchange2010":

[ewsHeaders:protected] => Array
                        (
                            [version] => SoapHeader Object
                                (
                                    [namespace] => http://schemas.microsoft.com/exchange/services/2006/types
                                    [name] => RequestServerVersion Version="Exchange2010"
                                    [mustUnderstand] => 
                                )

                            [impersonation] => 
                            [timezone] => 
                        )

...

            [username:protected] => 
            [primarySmtpMailbox:protected] => 
            [drillDownResponses:protected] => 1
            [version:protected] => Exchange2010
            [options:protected] => 
            [timezone:protected] => 

I added a 4th parameter to API::withUsernameAndPassword() to look like this:

$api = API::withUsernameAndPassword('EXCHANGESERVER', 'DOMAIN\MYUSERNAME', 'PASSWORDIMNOTTELLINGYOU', Array("version" => 'Exchange2007_SP3' ));

Which corrects the information in the garethp\ews\API object, but when I let the script load entirely, I still get

PHP Fatal error: Uncaught SoapFault exception: [soap:Client] The specified server version is invalid. in /var/www/html/php-ews-master/src/API/NTLMSoapClient.php:127

At this point I'm kinda stuck, because I cannot get any of the examples to work. I double-checked my version number on the exchange server, which is 08.03.0379.002 ( = RU14 for Exchange 2007 SP3 accoording to Microsoft TechNet ) , So I'm pretty sure that I DO have the valid server version, opposite to what the SoapClient->__call() method in NTLMSoapClient.php tells me.

Any suggestions are more than welcome.

Best regards,
JB

@Garethp
Copy link
Owner

Garethp commented Jun 8, 2016

Huh. You're right, my documentation is wrong. I recently changed it to default to Exchange 2010. Can you do a var_dump($request) on NTLMSoapClient::__doRequest()? It should return the XML that's going to be sent over to the server. Maybe the option overriding isn't working as I expect it to...

@marvelade
Copy link
Author

The result of adding var_dump($request) to NTLMSoapClient::__doRequest() is

string(578) " Default "

which strikes me as very odd, since I was always assuming that the number between parentheses denoted the number of characters for the string that followed.

Is this at all helpful?

@marvelade
Copy link
Author

marvelade commented Jun 9, 2016

Btw : I just found out that my exchange 2007 server is having an identity crisis and thinks it's Exchange 2013:

[https://ibin.co/2k2rKQ738jGA.jpg]

How can I change this property?

@marvelade
Copy link
Author

Another thing : If I change the server version in the php script to Exchange2007SP1, as user teadawg also had to do in (now closed) issue #41 (Direct link to the : #41 (comment) ) something changes.

Changing the 3 to a 1, there's still a Fatal (SOAP-related) Error, but it becomes a different one; it now is about failed schema validation:

PHP Fatal error:  Uncaught SoapFault exception: [soap11:Client] The request failed schema validation: The 'Id' attribute is invalid - The value 'Calendar' is invalid according to its datatype 'http://schemas.microsoft.com/exchange/services/2006/types:DistinguishedFolderIdNameType' - The Enumeration constraint failed. in /var/www/html/php-ews-master/src/API/NTLMSoapClient.php:127

Stack trace:

#0 /var/www/html/php-ews-master/src/API/NTLMSoapClient.php(127): SoapClient->__call('GetFolder', Array)

#1 /var/www/html/php-ews-master/src/API/ExchangeWebServices.php(294): garethp\\ews\\API\\NTLMSoapClient->__call('GetFolder', Array)

#2 /var/www/html/php-ews-master/src/API.php(295): garethp\\ews\\API\\ExchangeWebServices->__call('GetFolder', Array)

#3 /var/www/html/php-ews-master/src/API.php(295): garethp\\ews\\API\\ExchangeWebServices->GetFolder(Object(garethp\\ews\\API\\Type))

#4 /var/www/html/php-ews-master/src/API.php(313): garethp\\ews\\API->getFolder(Array)

#5 /var/www/html/php-ews-master/examples/basic/quickstart.php(21): garethp\\ews\\API->getFo in /var/www/html/php-ews-master/src/API/NTLMSoapClient.php on line 127

I don't know if you're actually supposed to browse to that URL (http://schemas.microsoft.com/exchange/services/2006/types:DistinguishedFolderIdNameType), but its HTML response isn't what I'd expect:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

In any case, thanks for taking some time out of your schedule to look in to this.

Best regards,
JB

@Garethp
Copy link
Owner

Garethp commented Jun 9, 2016

Well... your server is being weird.

As for the result of your var_dump, you're right, the number is the character count. I'm guessing that since the result is XML, it's being rendered in to... blankness. Check the source code of the page when the var_dump is there to see the full XML.

As for the URL, it's not meant to be visitable, but it's rather like an identifier. It's a namespace for XML. That being said, it looks like you're trying to use the value Calendar as a distinguished FolderName, right? The name is case-sensitive, and the correct value is calendar. For a list of all DistinguishsedFolderId's see the class Enumeration\DistinguishedFolderIdNameType.

If you're not specifically typing in Calendar as the folder name, can you paste your code so I can se where the error is? You shouldn't be, because the default folder it picks is the calendar folder anyway, so I'm wondering if it's not a bug in my code, but can you check that you're not manually passing it in anyway? Thanks

@Garethp
Copy link
Owner

Garethp commented Jun 15, 2016

Were you able to solve this issue?

@Garethp
Copy link
Owner

Garethp commented Jun 21, 2016

Is this issue still bothering you, or were you able to work through it?

@marvelade
Copy link
Author

I'm sorry, I thought I'd responded already, but apparently my comment was not submitted at that time. Indeed, I had replaced "Calendar" with some other values while testing when the server version was still Exchange2007_SP3. Eventhough I AM runnning 2007 SP3, I need to set this value to Exchange2007_SP1 in order for it to work. After changing that, I made a typo and wrote "calendar" instead of "Calendar". Capitalizing the C again made it work (which is the first time I've experienced case-sensitivity on Windows, yet the error was completely on my part).

Regarding the need to input the "wrong" server version: Is this a bug in your code? or is this an Exchange declaration problem?

Best regards,
JB

@Garethp
Copy link
Owner

Garethp commented Jun 21, 2016

Thanks for reminding me about that. I had forgotten that was the original issue, as opposed to the naming. It appears to be my fault. When I originally forked from jamesiarmes/php-ews, the constants for Exchange2007_SP2 and Exchange2007_SP3, and after confirming they exist, I just left them there. But on second look, now that I know a lot more about Exchange and EWS, it looks like there are less EWS versions than there are Exchange versions.

So there is no such thing as Exchange 2007 SP2 and SP3 for EWS. It looks like while SP2 and SP3 were released with bug fixes and so on, the API behind EWS didn't change, so there were no new versions of the Schema to be released. I hadn't noticed this, because I've been developing against a 2010 server, a 2013 server and now Office 365. In my next release I'll be removing those constants that don't actually exist. Thanks for pointing that out.

@Garethp Garethp closed this as completed Jun 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants