OfficeDev / ews-managed-api

Other
585 stars 319 forks source link

GetUserPhoto method - Response without ContentType results in exception thrown #111

Open cristianvasuica opened 7 years ago

cristianvasuica commented 7 years ago

Method: GetUserPhoto If happened in a production environment that the response received from an Office365 Exchange server that didn't had the ContentType element and when calling method "GetUserPhoto" an exception is thrown. The exception message is "The expected XML node type was Element, but the actual type is EndElement".

After some investigations I found that if the reponse returned by the Exchange server doesn't contain a "ContentType", in the method "ReadElementsFromXML" of class "GetUserPhotoResponse" at line 69 where the ContentType is read the exception is thrown.

I have attached a capture of the response taken with Fiddler. The PictureData was removed and can be replaced with any Base64 enconding of a jpg picture.

<?xml version="1.0" encoding="UTF-8"?>
-<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
-<s:Header>
<h:ServerVersionInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" Version="V2017_01_07" MinorBuildNumber="11" MajorBuildNumber="1005" MinorVersion="1" MajorVersion="15"/>
</s:Header>
-<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-<GetUserPhotoResponse xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" ResponseClass="Success">
<ResponseCode>NoError</ResponseCode>
<HasChanged>true</HasChanged>
<PictureData>Some Base64 encoded jpg</PictureData>
</GetUserPhotoResponse>
</s:Body>
</s:Envelope>

If the picture is downloaded in the browser then the picture is saved on the disk without an extension. Below you can find the sample url used to download the picture. https://outlook.office365.com/ews/Exchange.asmx/s/GetUserPhoto?email=someemail@company.com&size=HR240x240

Exchange version: Exchange2013_SP1 on a Office365 instance If need any other info just let me know.