private string Signature(KalturaParams kparams)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            byte[] data = Encoding.ASCII.GetBytes(kparams.ToJson());
            data = md5.ComputeHash(data);
            StringBuilder sBuilder = new StringBuilder();

            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }
            return(sBuilder.ToString());
        }
        public XmlElement DoQueue()
        {
            if (_CallsQueue.Count == 0)
            {
                resetRequest();
                return(null);
            }

            DateTime startTime = DateTime.Now;

            this.Log("service url: [" + this._Config.ServiceUrl + "]");

            KalturaParams kparams = new KalturaParams();
            KalturaFiles  kfiles  = new KalturaFiles();

            foreach (string param in clientConfiguration.Keys)
            {
                kparams.Add(param, clientConfiguration[param].ToString());
            }
            kparams.AddIfNotNull("format", this._Config.ServiceFormat.GetHashCode());

            string url = this._Config.ServiceUrl + "/api_v3";

            if (_MultiRequestReturnType != null)
            {
                url += "/service/multirequest";
                int i = 1;
                foreach (KalturaServiceActionCall call in _CallsQueue)
                {
                    KalturaParams callParams = call.GetParamsForMultiRequest(i);
                    kparams.Add(callParams);
                    KalturaFiles callFiles = call.GetFilesForMultiRequest(i);
                    kfiles.Add(callFiles);
                    i++;
                }

                // map params
                foreach (KeyValuePair <string, IKalturaSerializable> item in _MultiRequestParamsMap)
                {
                    string requestParam = item.Key;
                    IKalturaSerializable resultParam = item.Value;

                    if (kparams.ContainsKey(requestParam))
                    {
                        kparams[requestParam] = resultParam;
                    }
                }
            }
            else
            {
                KalturaServiceActionCall call = _CallsQueue[0];
                url += "/service/" + call.Service + "/action/" + call.Action;
                kparams.Add(call.Params);
                kfiles.Add(call.Files);
            }

            kparams.Add("kalsig", this.Signature(kparams));
            string json = kparams.ToJson();

            this.Log("full reqeust url: [" + url + "]");
            this.Log("full reqeust data: [" + json + "]");

            // build request
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);

            if (kfiles.Count == 0)
            {
                request.Timeout = _Config.Timeout;
            }
            else
            {
                request.Timeout = Timeout.Infinite;
            }
            request.Method = "POST";
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            request.Headers = _Config.RequestHeaders;
            request.Accept  = "application/xml";

            // Add proxy information if required
            createProxy(request, _Config);

            if (kfiles.Count > 0)
            {
                this.PostMultiPartWithFiles(request, json, kfiles);
            }
            else
            {
                this.PostUrlEncodedParams(request, json);
            }

            // get the response
            using (WebResponse response = request.GetResponse())
            {
                Encoding     enc            = System.Text.Encoding.UTF8;
                StreamReader responseStream = new StreamReader(response.GetResponseStream(), enc);
                string       responseString = responseStream.ReadToEnd();

                this._ResponseHeaders = response.Headers;
                string serverName    = null;
                string serverSession = null;
                for (int i = 0; i < this._ResponseHeaders.Count; ++i)
                {
                    if (this._ResponseHeaders.Keys[i] == "X-Me")
                    {
                        serverName = this._ResponseHeaders[i];
                    }
                    if (this._ResponseHeaders.Keys[i] == "X-Kaltura-Session")
                    {
                        serverSession = this._ResponseHeaders[i];
                    }
                }
                if (serverName != null || serverSession != null)
                {
                    this.Log("server: [" + serverName + "], session: [" + serverSession + "]");
                }

                this.Log("result (serialized): " + responseString);

                DateTime endTime = DateTime.Now;

                this.Log("execution time for [" + url + "]: [" + (endTime - startTime).ToString() + "]");

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(responseString);

                this.ValidateXmlResult(xml);
                XmlElement result = xml["xml"]["result"];
                this.ThrowExceptionOnAPIError(result);

                if (!IsMultiRequest)
                {
                    resetRequest();
                }

                return(result);
            }
        }