none
Data is Corrupt Exception while calling ExchangeService.ConvertId EWSManagedAPI RRS feed

  • Question

  • Hi Glen,

    I am using EWSManagedAPI for 2010. I need to generate OWA email item url for office 365 account. The itemid I get from exchange using EWSManagedAPI is OWAID and the new OWA uses EWSID. So I have got following code to convert OWAID to EWSID. But I am getting "Data is Corrupt" exception:-(. Please help. Thank you!

    AlternateId originalId = new AlternateId(IdFormat.OwaId, idToConvert, mailboxSMTP, false);

     // Send a request to convert the item identifier. This results in a call to EWS.
    AlternateId newId = service.ConvertId(originalId, IdFormat.EwsId) as AlternateId;

    Monday, January 6, 2014 1:25 PM

All replies

  • WithWith Office365 the OWAid actually contains the EWSId so you just need to parse it out to use it . In the recent update they fixed the issue with the WebClientReadFormQueryString http://msdn.microsoft.com/en-us/library/dd877102(v=exchg.150).aspx but as documented ConvertId is only for 2007 and 2010.

    eg the following should work okay to convert a office365URI to and EWSId you can bind to

                String owaString = "https://outlook.office365.com/owa/#viewmodel=ReadMessageItem&ItemID=AAMkADg2NTdjNjI4LTQwZGUtNDljYy1hMzUwLTM4NTg4ZDExNWIzMwBGAAAAAACzWmFnBc%2BwRZtugwgkD3EbBwAZoJ4atq4oTZ97MnY2SLrbAAAAAAENAAAZoJ4atq4oTZ97MnY2SLrbAAA3MErmAAA%3D&ViewFilter=All&ClutterFilter=All&wid=65&ispopout=1";
                NameValueCollection queryParameters = new NameValueCollection();
                string[] querySegments = owaString.Split('&');
                foreach (string segment in querySegments)
                {
                    string[] parts = segment.Split('=');
                    if (parts.Length > 0)
                    {
                        string key = parts[0].Trim(new char[] { '?', ' ' });
                        string val = Uri.UnescapeDataString(parts[1].Trim());
                        
                        queryParameters.Add(key, val);
                    }
                }
                EmailMessage ewsEmail = EmailMessage.Bind(service, new ItemId(queryParameters["ItemID"]));
    Cheers
    Glen

    Tuesday, January 7, 2014 6:51 AM
  • Hi Glen,

    Thanks for your response. But let me clarify a bit more as to what I am doing.

    I am binding to user's inbox using user's exchange service url using EWSManagedAPI for exchange2010SP1. Then I retrieve the emailitemid usingEmailMessage.WebClientReadFormQueryString which is OWAID and I build each email item's url separately so that the user can click on it from my application itself without having to loginto OWA separately. But since our user's account has been upgraded to use NEW Outlook WebApp this url that I generate is NOT working anymore as the new outlook webapp is using the EWSID.

    So here is the url I generate which works for older version of OWA but not for the latest version:

    https://ch1prd0210.outlook.com/owa/?ae=Item&a=Open&t=IPM.Note&id=RgAAAAAwwHepFYCETIIvaOdO6eCsBwBz58e3T7WJRaIRf7oLIKA0AAAADaHyAACCjYcMRqtoTZAePDKaN4kdAAAa0n9qAAAJ&exvsurl=1

    For the latest version the id in there should be EWSID and not OWAID. which looks like what you have pasted above. So basically I want to build url like following. Please help.

    https://outlook.office365.com/owa/#viewmodel=ReadMessageItem&ItemID=AAMkADg2NTdjNjI4LTQwZGUtNDljYy1hMzUwLTM4NTg4ZDExNWIzMwBGAAAAAACzWmFnBc%2BwRZtugwgkD3EbBwAZoJ4atq4oTZ97MnY2SLrbAAAAAAENAAAZoJ4atq4oTZ97MnY2SLrbAAA3MErmAAA%3D&ViewFilter=All&ClutterFilter=All&wid=65&ispopout=1

    Tuesday, January 7, 2014 10:10 AM
  • If you want to go the other way you can just use something simular eg the following works okay for me.

                String owaString = "https://outlook.office365.com/owa/#viewmodel=ReadMessageItem&ItemID=";
                String owaString2 = "&ViewFilter=All&ClutterFilter=All&wid=65&ispopout=1";
                FindItemsResults<Item> fiResults = service.FindItems(WellKnownFolderName.Inbox,new ItemView(1));
                if(fiResults.Items.Count ==1){
                    String userOWAurl = owaString + Uri.EscapeDataString(fiResults.Items[0].Id.UniqueId) + owaString2;
                }

    (Probably the main problem your having is that you need to make sure you escape the Base64 used in the EWSId for it to work correctly).

    Cheers
    Glen

    Tuesday, January 7, 2014 10:30 PM
  • Hi Glen,

    Thanks so much for spending time and replying.

    I have one more query w.r.t. this. I am in the process of writing a portal for live@edu for a school where in the school's portal we bind to the inbox for a student where we show all the email items and for every email item I build/generate a link which has singlesignontoken plus OWA item url in querystring. There is single sign on involved in this as this first goes to login.microsoftonline.com with the token and the server then redirects to the above OWA item url. All of this used to work before a student's account was migrated to new OWA(office365). But after its been migrated, when clicked on the link through the school's portal, instead of opening the item in OWA, I am getting "440 login timeout" error, which is strange because it hardly takes a second to pop up the error. But I feel the login still takes place because when I paste the email url manually in a new tab , that works and shows the OWA email item.

    The OWA item url is like following:

    https://outlook.office365.com/owa/#viewmodel=ReadMessageItem&ItemID=AAMkAGY3MGVlZTNjLWRkNDgtNDhjOC1iNzY1LWVkYmY1ODBiN2YzNABGAAAAAAAwwHepFYCETIIvaOdO6eCsBwBz58e3T7WJRaIRf7oLIKA0AAAADaHyAACCjYcMRqtoTZAePDKaN4kdAAAgJcY6AAA%3D

    Please help if you can!

    Thanks,

    Sampada.

    Thursday, January 9, 2014 5:34 PM