Created
May 31, 2016 08:15
-
-
Save ahelland/ca716459245cbde1854e375162633cb9 to your computer and use it in GitHub Desktop.
BlobTriggered Function for processing WBXML returned from Exchange ActiveSync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "EAS Protocol.dll" | |
#r "System.Xml.Linq.dll" | |
using System; | |
using System.Xml.Linq; | |
using EAS_Protocol.WBXML; | |
public static void Run(string myBlob, TraceWriter log) | |
{ | |
log.Info($"C# Blob trigger function processed: {myBlob}"); | |
var response = myBlob.Split(';'); | |
log.Info($"Guid: {response[0]}, Content: {response[1]}"); | |
System.Text.UTF8Encoding utf8Encoding = new System.Text.UTF8Encoding(); | |
Byte[] byteResp = utf8Encoding.GetBytes(response[1]); | |
WBXMLWriter wbxmlWriter = new WBXMLWriter(new ASCodePageProvider()); | |
WBXMLConverter wbxmlConverter = new WBXMLConverter(new ASCodePageProvider(), wbxmlWriter, null); | |
XElement destXml = wbxmlConverter.Parse(byteResp); | |
var responseBody = destXml.ToString(); | |
log.Info($"WBXML:{System.Environment.NewLine}{destXml.ToString()}"); | |
if(responseBody.Contains("101") == true) | |
{ | |
//Technically an indication your XML isn't all there for an actual client, but for a test case it is all good :) | |
} | |
if (responseBody.Contains("108") == true) | |
{ | |
// The device ID is invalid. | |
// Are you using any special characters? Only plain characters and numerals recommended. | |
} | |
if (responseBody.Contains("126") == true) | |
{ | |
// The user account does not have permission to synchronize. | |
// This could also be due to using an admin account. (Domain admin is not allowed to sync by default.) | |
} | |
//if EAS >= 12.1 (Exchange 2007 SP1) we need to parse the returned wbxml for '142' to find out if we need to provision | |
//EAS 12.0 indicates the same status through HTTP 449 | |
var strEASVersion = "14.1"; | |
if (strEASVersion == "12.1" || strEASVersion == "14.0" || strEASVersion == "14.1") | |
{ | |
if (responseBody.Contains("142") == true) | |
{ | |
// The response is ok, but you need to provision. | |
} | |
} | |
if (responseBody.Contains("141") == true) | |
{ | |
// Only provisionable devices are allowed to sync, and you seem to be non-provisionable. | |
// Check "Provisionable device" and run the test again. | |
} | |
if (responseBody.Contains("140") == true) | |
{ | |
// A remote wipe has been issued for your device. | |
// Choose "Remote Wipe (Emulated)" to simulate a wipe. | |
} | |
if (responseBody.Contains("144") == true) | |
{ | |
// The device's policy key is invalid. The policy has probably changed on the server. The device needs to re-provision. | |
// This may happen if you have synced a "device" with security policies and then removed the support for all policies. | |
} | |
else if (responseBody.Length <= 15) | |
{ | |
// More status codes can be looked up here: | |
// http://msdn.microsoft.com/en-us/library/ee218647(v=EXCHG.80).aspx | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment