Visual C#: transfer of SOAP protocol files



  • I'm writing Windows Services, which is supposed to transfer to servers files from a given catalogue, and after successful transmission, erase them. Decided to write a test program to check SOAP requests. I generated SOAP queries from WSDL file. I.D.'s been fine, the server files are gone, too. Problems started at a time when I started removing the foiled files. At first, I tried to remove them immediately after they were sent and then I got an exception.

    "Delete Error: The process can't access the file "C:\ElarService\current_sessions\gjeboldov@elar.ru\1.jpg), as this file is used in another process."

    Then I decided to remove the files after they all leave. Five files were sent, after which they were removed. As a result, the first three were removed and the last two were the exception mentioned above. Here's SOAP demand code:

        public string SaveImage(string SessionID, [System.Xml.Serialization.XmlElementAttribute(DataType="integer")] string NumberPage, [System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] byte[] Image, [System.Xml.Serialization.XmlElementAttribute(DataType="integer")] string FileLength) {
        object[] results = this.Invoke("SaveImage", new object[] {
                    SessionID,
                    NumberPage,
                    Image,
                    FileLength});
        return ((string)(results[0]));
    }
    

    Function where the request is made:

            public static int SendFiles()
        {
            string[] files = Directory.GetFiles(WorkingDir);
            int count = 0;
    
        IsDelete = 0;
        List.Clear();
    
        foreach (var name in files)
        {
            Image img = Image.FromFile(name);
            Console.WriteLine("File: " + name);
            ImageConverter conv = new ImageConverter();
            byte[] arr = (byte[]) conv.ConvertTo(img, typeof (byte[]));
            if (arr != null)
            {
                int retCode;
    
                var answer = Request.SaveImage(SessionId, Convert.ToString(count), arr, Convert.ToString(arr.Length));
                int.TryParse(answer, out retCode);
                Console.WriteLine("In SendFiles foreach result = {0}, count = {1}", retCode, count);
                if (retCode != 1)
                {
                    IsDelete = 1;
                    List.Add(0);
                }
                else
                {
                    List.Add(1);
                }
            }
            count++;
        }
        return 0;
    }
    

    File disposal function:

            public static void DeleteFiles()
    {
    string[] files = Directory.GetFiles(WorkingDir);
    for (int i = 0; i < List.Count; i++)
    {
    if (List[i] == 1)
    {
    try
    {
    File.Delete(files[i]);
    }
    catch (Exception e)
    {
    Console.WriteLine("Delete Error: " + e.Message);
    }
    }
    }
    if (IsDelete == 0)
    {
    try
    {
    Directory.Delete(WorkingDir);
    }
    catch (Exception e)
    {
    Console.WriteLine("Directory delete error: " + e.Message);
    }
    }
    }

    Well, actually, the question is, what can block the file? I'm sorry, I'm new at C#, this is my first experience.

    P.S. I was ten seconds late.



  • Image img = Image.FromFile(name);

    The picture is an unmanageable resource. Put it down. using

    PS, what does SOAP mean? There's no magic, the server can't remotely block a file that's transposed as a bayte.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2