Skip to content

Instantly share code, notes, and snippets.

@ahelland
Created May 31, 2016 08:04
Show Gist options
  • Save ahelland/d59ab837cfec72f217c73673c55f77d6 to your computer and use it in GitHub Desktop.
Save ahelland/d59ab837cfec72f217c73673c55f77d6 to your computer and use it in GitHub Desktop.
QueueTriggered Function for processing HTTP Status Codes returned from Exchange ActiveSync
using System;
public static void Run(string myQueueItem, out object statusDocument, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
var status = myQueueItem.Split(';');
log.Info($"Guid: {status[0]}, StatusCode: {status[1]}");
var guid = status[0];
var resCode = status[1];
//Always output to a doc db so we can pull stats later
statusDocument = new {
id = guid,
status = resCode,
timeStamp = DateTime.UtcNow
};
if (resCode == "200")
{
//All is good on the HTTP side
//WBXML parsed outside this function
}
if (resCode == "302")
{
// Explanation:
// Server issued a redirect to a new URL. You should issue a new Autodiscover (and change FQDN).
// Status: Further action required.
}
if(resCode == "400")
{
// Explanation:;
// Possibly a protocol mismatch, for example using version 14.0 against an Exchange 2007 server.
// Choose a different protocol version to emulate, and try to run test again.
// Status: FAIL
}
if (resCode == "401")
{
// Explanation:
// Wrong username/password. May also occur if you're using a reverse proxy which performs authentication.
// Could also be caused by authenticating with user@domain.com if Active Directory doesn't accept this.
// Status: FAIL";
}
if (resCode == "403")
{
//EAS version indicates which Exchange Server version we're emulating
//Hardwire to Exchange 2013
var strEASVersion = "14.1";
if (strEASVersion == "12.0" || strEASVersion == "12.1")
{
// Explanation:
// You are either running a non-provisionable device, or a provisionable device that haven't been provisioned yet.
// First check: Tick off "Provisionable device" and run test again.
// Second check Tick off "Support security policies" and run test again.
// Status: Further action required
}
else
{
// Explanation:
// The server requires SSL and will not let you connect over HTTP.
// (For instance trying to connect over HTTP while IIS requires SSL.)
// Status: Further action required
}
}
if (resCode == "404")
{
// Explanation:
// File not found shouldn't occur...check IIS that files are not missing, and that the endpoint is correct.
// Status: FAIL
}
if (resCode == "449")
{
//We don't support provisioning client-side so we hardwire this result
var bProvisionable = false;
if (bProvisionable == false)
{
// Explanation:
// You seem to be using a non-provisionable device.
// Check "Provisionable device" and run test again.
// Status: Further action required
}
else
{
// Explanation:
// You seem to be running a provisionable device, but will need to apply policies before sync is allowed.
// Check "Support security policies" and run test again.
// Status: Further action required
}
}
if (resCode == "451")
{
// Explanation:
// Redirect request. Your mailbox is located on a different server.
// Address returned by Exchange: " + httpEx.Response.Headers.Get("X-MS-Location")
// Please change the FQDN part in the "Server Address" field.
// Status: Further action required
}
//Note: 501 & 505 should only occur when doing GET, not POST
if (resCode == "501" || resCode == "505")
{
// Explanation:
// This is correct behaviour, and means your Exchange server is responding!
// Status: PASS
}
if (resCode == "502")
{
// Explanation:
// There is a server available at this FQDN and this port, but it's not responding to your request.
// Could for instance happen if http://contoso.com does not redirect to an Exchange server.
// Status: FAIL
}
if (resCode == "503")
{
// Explanation:
// You server is either experiencing too much load, or in a maintenance mode.
// Check again in a short while, and if problem persists check that all services are running on your Exchange server.
// Status: FAIL
}
if (resCode == "504")
{
// Explanation:
// Seems your Exchange server might have problems on the back end connecting to other servers (possibly Active Directory).
// Check network connectivity on your Exchange server. (Problem most likely not between ActiveSync client and Exchange.)
// Status: FAIL
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment