/// <remarks/>
 public void RetrieveItemAsync(RetrieveItemRequest RetrieveItemRequest, object userState)
 {
     if ((this.RetrieveItemOperationCompleted == null))
     {
         this.RetrieveItemOperationCompleted = new System.Threading.SendOrPostCallback(this.OnRetrieveItemOperationCompleted);
     }
     this.InvokeAsync("RetrieveItem", new object[] {
             RetrieveItemRequest}, this.RetrieveItemOperationCompleted, userState);
 }
 /// <remarks/>
 public System.IAsyncResult BeginRetrieveItem(RetrieveItemRequest RetrieveItemRequest, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("RetrieveItem", new object[] {
             RetrieveItemRequest}, callback, asyncState);
 }
 /// <remarks/>
 public void RetrieveItemAsync(RetrieveItemRequest RetrieveItemRequest)
 {
     this.RetrieveItemAsync(RetrieveItemRequest, null);
 }
        /// <summary>
        /// Retorna a lista de arquivos no servidor associada a um Id
        /// </summary>
        /// <param name="idContent">Chave de busca</param>
        /// <returns>Lista de arquivos</returns>
        public List<byte[]> GetFiles(string idContent)
        {
            List<byte[]> files = new List<byte[]>();

            // Cria uma nova instancia do WebServices 
            IR4CorrespProxy content = new IR4CorrespProxy();

            content.RequireMtom = true;

            // Aponta a instancia atual do WebService para a URL de desenvolvimento: 
            content.Url = _url; //"http://cmdes.itau/CMBSpecificWebService/services/CMWebService";

            // Aponta a instancia atual do WebService para a URL de produção: 
            //content.Url = http://cmcorp2.itau/CMBSpecificWebService/services/CMWebService"; 
            // Cria uma requisição de consulta de arquivos 
            RetrieveItemRequest Request = new RetrieveItemRequest();
            // Autenticação 
            Request.AuthenticationData = new AuthenticationData();
            Request.AuthenticationData.ServerDef = new ServerDef();
            //Request.AuthenticationData.ServerDef.ServerName = "NLSDB01"; // PRODUCAO 
            Request.AuthenticationData.ServerDef.ServerName = _serverName;// "NLSDBDES";  // DESENVOLVIMENTO 
            Request.AuthenticationData.ServerDef.ServerType = ServerType.ICM;
            Request.AuthenticationData.LoginData = new AuthenticationDataLoginData();
            Request.AuthenticationData.LoginData.UserID = _username;// "USUARIO";
            Request.AuthenticationData.LoginData.Password = _password; // "SENHA";

            Request.retrieveOption = RetrieveItemRequestRetrieveOption.CONTENT;
            Request.contentOption = RetrieveItemRequestContentOption.ATTACHMENTS;
            Request.Item = new RetrieveItemRequestItem[1];
            Request.Item[0] = new RetrieveItemRequestItem();
            Request.Item[0].URI = idContent; // ID DO DOCUMENTO 

            RetrieveItemReply reply = content.RetrieveItem(Request);
            if (reply.RequestStatus.success)
            {
                MTOMAttachment[] attachments = reply.mtomRef;

                for (int j = 0; j < attachments.Length; j++)
                {
                    string id = attachments[j].ID;
                    files.Add(attachments[j].Value);
                }
            }
            else
            {
                //Console.WriteLine("Falha ao criar arquivo"); 
                ErrorData[] err = reply.RequestStatus.ErrorData;
                string errorStack = "";
                for (int i = 0; i < err.Length; i++)
                {
                    errorStack += "Item: " + err[i].Item + " Code: " + err[i].returnCode + "Stack: " + err[i].stackTrace + "\n";
                }
                throw new Exception(errorStack);
            }
            return files;
        }