none
The Export and Upload sample codes from Microsoft website RRS feed

  • Question

  • Hi,

    I am writing our own exchange migration tool using the sample export and upload sample codes provided by microsoft website. The sample codes is working for using individual user credentials but not for using impersonation. I have already granted the impersonation role to my admin ac. Please help.

    The source codes can be found in this website :

    http://msdn.microsoft.com/library/hh135142(EXCHG.140).aspx

    When using impersonation, the export portion of the codes is still ok, but when it reached the upload statement, it fails... I pasted the failed statement here :

    UploadItemsResponseType upLoadResponse = DestinationEsb.UploadItems(upUploadItems);

    The initial error message is "ParentFolderID" not found ! After taking advice from Microsoft staff, we added the

    fifolderId.ChangeKey = uploadFolder.Id.ChangeKey;

    statement. Now, the new error is below...

    The error message can be found in the XML response here :


    <?xml version="1.0" encoding="UTF-8"?>
    -<UploadItemsResponseType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> -<ResponseMessages xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"> -<UploadItemsResponseMessage ResponseClass="Error"> <MessageText>The specified object was not found in the store.</MessageText> <ResponseCode>ErrorItemNotFound</ResponseCode> <DescriptiveLinkKey>0</DescriptiveLinkKey> </UploadItemsResponseMessage> -<UploadItemsResponseMessage ResponseClass="Error"> <MessageText>The specified object was not found in the store.</MessageText> <ResponseCode>ErrorItemNotFound</ResponseCode> <DescriptiveLinkKey>0</DescriptiveLinkKey> </UploadItemsResponseMessage> -<UploadItemsResponseMessage ResponseClass="Error"> <MessageText>The specified object was not found in the store.</MessageText>

    Please help...

    Monday, January 9, 2012 1:50 AM

Answers

  • Those errors are pointing more to a permissions errors if your using Impersonation make sure you have set this up properly using RBAC if your using Exchange Online see http://msdn.microsoft.com/en-us/library/gg194012(v=EXCHG.140).aspx   also as a general rule you shouldn't be using Administrative account to test an application from a permission perspective any account with administrative rights will be specifically denied access to every mailbox other then their own so my suggestion is follow best practice and create an account specifically for this purpose.

    More specific to that sample if your going to use impersonation make sure you have set Impersonation up on both the EWS Managed API and Proxy Code if your using Exchange Online you also need to make sure you set the Cookies for your proxy code. Eg the following is a sample that works fine against Exchange Online using Impersonation.

                ExchangeService service = new ExchangeService();
                ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
                NetworkCredential ncNetworkCredential = new NetworkCredential("glen@domain.onmicrosoft.com", "password", "");
                service.Credentials = ncNetworkCredential;
                service.AutodiscoverUrl("pstimport@messageops.com", delegate { return true; });
                service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "import@domain.onmicrosoft.com");
                ExchangeServiceBinding esb = new ExchangeServiceBinding();
                esb.Credentials = ncNetworkCredential;
                esb.CookieContainer = service.CookieContainer;
                esb.Url = service.Url.ToString();
                esb.RequestServerVersionValue = new RequestServerVersion();
                esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010_SP1;
                esb.ExchangeImpersonation = new ExchangeImpersonationType();
                ExchangeImpersonationType exType = new ExchangeImpersonationType();
                ConnectingSIDType CSIDType = new ConnectingSIDType();
                CSIDType.Item = "import@domain.onmicrosoft.com";
                CSIDType.ItemElementName = ItemChoiceType.PrimarySmtpAddress;
                exType.ConnectingSID = CSIDType;
                esb.ExchangeImpersonation = exType;
                uploadItem(esb, service, "c:\\npexp.fts");
    

    static void uploadItem(ExchangeServiceBinding esb, ExchangeService service, String fileName)
            {
                byte[] MessageBytes = null;
                FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                long numBytes = new FileInfo(fileName).Length;
                MessageBytes = br.ReadBytes((int)numBytes);
                UploadItemType upUploadItem = new UploadItemType();
                upUploadItem.CreateAction = CreateActionType.CreateNew;
                upUploadItem.Data = MessageBytes;
                upUploadItem.IsAssociatedSpecified = true;
                upUploadItem.IsAssociated = false;
                FolderIdType fiFolderid = new FolderIdType();
                Folder uploadFolder = Folder.Bind(service, WellKnownFolderName.Inbox);
                fiFolderid.Id = uploadFolder.Id.UniqueId;
                upUploadItem.ParentFolderId = fiFolderid;
                UploadItemsType upUploadItems = new UploadItemsType();
                upUploadItems.Items = new UploadItemType[1];
                upUploadItems.Items[0] = upUploadItem;
                UploadItemsResponseType upLoadResponse = esb.UploadItems(upUploadItems);
                UploadItemsResponseMessageType upResponesType = (UploadItemsResponseMessageType)upLoadResponse.ResponseMessages.Items[0];
            }
    
    Cheers
    Glen

    Monday, January 9, 2012 4:50 AM

All replies

  • Those errors are pointing more to a permissions errors if your using Impersonation make sure you have set this up properly using RBAC if your using Exchange Online see http://msdn.microsoft.com/en-us/library/gg194012(v=EXCHG.140).aspx   also as a general rule you shouldn't be using Administrative account to test an application from a permission perspective any account with administrative rights will be specifically denied access to every mailbox other then their own so my suggestion is follow best practice and create an account specifically for this purpose.

    More specific to that sample if your going to use impersonation make sure you have set Impersonation up on both the EWS Managed API and Proxy Code if your using Exchange Online you also need to make sure you set the Cookies for your proxy code. Eg the following is a sample that works fine against Exchange Online using Impersonation.

                ExchangeService service = new ExchangeService();
                ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
                NetworkCredential ncNetworkCredential = new NetworkCredential("glen@domain.onmicrosoft.com", "password", "");
                service.Credentials = ncNetworkCredential;
                service.AutodiscoverUrl("pstimport@messageops.com", delegate { return true; });
                service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "import@domain.onmicrosoft.com");
                ExchangeServiceBinding esb = new ExchangeServiceBinding();
                esb.Credentials = ncNetworkCredential;
                esb.CookieContainer = service.CookieContainer;
                esb.Url = service.Url.ToString();
                esb.RequestServerVersionValue = new RequestServerVersion();
                esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010_SP1;
                esb.ExchangeImpersonation = new ExchangeImpersonationType();
                ExchangeImpersonationType exType = new ExchangeImpersonationType();
                ConnectingSIDType CSIDType = new ConnectingSIDType();
                CSIDType.Item = "import@domain.onmicrosoft.com";
                CSIDType.ItemElementName = ItemChoiceType.PrimarySmtpAddress;
                exType.ConnectingSID = CSIDType;
                esb.ExchangeImpersonation = exType;
                uploadItem(esb, service, "c:\\npexp.fts");
    

    static void uploadItem(ExchangeServiceBinding esb, ExchangeService service, String fileName)
            {
                byte[] MessageBytes = null;
                FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                long numBytes = new FileInfo(fileName).Length;
                MessageBytes = br.ReadBytes((int)numBytes);
                UploadItemType upUploadItem = new UploadItemType();
                upUploadItem.CreateAction = CreateActionType.CreateNew;
                upUploadItem.Data = MessageBytes;
                upUploadItem.IsAssociatedSpecified = true;
                upUploadItem.IsAssociated = false;
                FolderIdType fiFolderid = new FolderIdType();
                Folder uploadFolder = Folder.Bind(service, WellKnownFolderName.Inbox);
                fiFolderid.Id = uploadFolder.Id.UniqueId;
                upUploadItem.ParentFolderId = fiFolderid;
                UploadItemsType upUploadItems = new UploadItemsType();
                upUploadItems.Items = new UploadItemType[1];
                upUploadItems.Items[0] = upUploadItem;
                UploadItemsResponseType upLoadResponse = esb.UploadItems(upUploadItems);
                UploadItemsResponseMessageType upResponesType = (UploadItemsResponseMessageType)upLoadResponse.ResponseMessages.Items[0];
            }
    
    Cheers
    Glen

    Monday, January 9, 2012 4:50 AM
  • Hello Glen,

    Thank you very much for your sample codes.  I have solved the problem already after adding a few lines of codes... 

    Thank you everyone from Microsoft and have a nice day.

    Wednesday, January 11, 2012 9:36 AM