I am working on a C# based ActiveSync client and am running into issues when I am trying to post the Sendmail command to the server. I am testing with mime data in the following format:
var testMsg = @"From: [email protected]
To: [email protected]
Cc:
Bcc:
Subject: From NSync
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
VGhpcyBpcyB0aGUgYm9keSB0ZXh0Lg==";
var data = UTF8Encoding.UTF8.GetBytes(testMsg);
When the server gets the data, I get this exception in the Exchange client log:
Command_WorkerThread_Exception :
--- Exception start ---
Exception type: Microsoft.Exchange.AirSync.Wbxml.WbxmlException
Exception message: Invalid WBXML code/codepage from client
Exception level: 0
Exception stack trace: at Microsoft.Exchange.AirSync.Wbxml.WbxmlReader.ReadXmlDocument()
at Microsoft.Exchange.AirSync.AirSyncRequest.get_XmlDocument()
at Microsoft.Exchange.AirSync.Command.get_XmlRequest()
at Microsoft.Exchange.AirSync.Command.WorkerThread()
Inner exception follows...
Exception type: System.IndexOutOfRangeException
Exception message: Index was outside the bounds of the array.
Exception level: 1
Exception stack trace: at Microsoft.Exchange.AirSync.Wbxml.WbxmlSchema30.GetName(Int32 tag)
at Microsoft.Exchange.AirSync.Wbxml.WbxmlReader.FillXmlElement(XmlElement elem, Int32 depth, Boolean elemIsSecureData, Boolean elemIsBlobData)
at Microsoft.Exchange.AirSync.Wbxml.WbxmlReader.FillXmlElement(XmlElement elem, Int32 depth, Boolean elemIsSecureData, Boolean elemIsBlobData)
at Microsoft.Exchange.AirSync.Wbxml.WbxmlReader.ReadXmlDocument()
--- Exception end ---
I figured out that my issue had nothing to do with the message being sent. The issue had to do with the way we were serializing to WBXML.
When writing the Opaque data, for the MIME content, you need to first put the data length and after that but the byte array. My code to write the length of the data was off, which caused the issue.