How-to: Basic check for Exchange Web Services connectivity using code

When a program is about to start talking to Exchange there is the chance of some sort of connectivity problem which will cause its EWS calls to fail. A basic can EWS call can be done to see if EWS can be reached and process a basic request. Below is such a connectivity test call where a call to the EWS is done to convert the Id of an item from one form to another. This call should be processed and EWS respond with a 200 even though the conversion failed. What is important here is that EWS does process the request and reply with a 200 response – which means that the application can talk to EWS. If there was an issue such as one with authentication, then 401 would be returned.

 

Note that you can use any EWS call for checking connectivity. The example used here is what EwsEditor uses when you first log in.

 

Request:

 

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">

<soap:Header>

<t:RequestServerVersion Version="Exchange2013" />

</soap:Header>

<soap:Body>

<m:ConvertId DestinationFormat="HexEntryId">

<m:SourceIds>

<t:AlternateId Format="HexEntryId" Id="00" Mailbox="blah@blah.com" />

</m:SourceIds>

</m:ConvertId>

</soap:Body>

</soap:Envelope>

 

Response:

 

HTTP/1.1 200 OK

Transfer-Encoding: chunked

Content-Encoding: gzip

Vary: Accept-Encoding

request-id: b0493d2e-ac19-4199-8be3-b413149b9317

client-request-id: 945f0cef-60f6-4813-be00-7cb5eee92240

( The header is truncated )

 

<?xml version="1.0" encoding="utf-8"?>

<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">

<s:Header>

<h:ServerVersionInfo MajorVersion="15" MinorVersion="1" MajorBuildNumber="1157" MinorBuildNumber="22" Version="V2017_04_14" xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" />

</s:Header>

<s:Body>

<m:ConvertIdResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">

<m:ResponseMessages>

<m:ConvertIdResponseMessage ResponseClass="Error">

<m:MessageText>Data is corrupt., Store ID isn't an ID of a folder, item or mailbox.</m:MessageText>

<m:ResponseCode>ErrorCorruptData</m:ResponseCode>

<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>

</m:ConvertIdResponseMessage>

</m:ResponseMessages>

</m:ConvertIdResponse>

</s:Body>

</s:Envelope>