CSWA_Integration.Helper.pullDoc C# (CSharp) Метод

pullDoc() публичный статический Метод

public static pullDoc ( string i_DocId, string i_SessionId ) : string
i_DocId string
i_SessionId string
Результат string
        public static string pullDoc(string i_DocId, string i_SessionId)
        {
            string docPath = null;

            // Sending a GET request to pullSignedDoc.aspx page with the proper session ID
            string response = SendRequest(CSWAPath + "Sign/DownloadSignedFileG" + "?sessionId=" + i_SessionId, null, null, "GET");

            // If the request was handled successfully the response XML should include a success return code (0), the last signature details and the signed document.
            XmlDocument xml = new XmlDocument();
            xml.LoadXml(response);
            string returnCode = xml.DocumentElement.GetElementsByTagName("returnCode")[0].InnerText;

            if (returnCode != SUCCESS)
            {
                throw new Exception("Pull doc error: " + xml.DocumentElement.GetElementsByTagName("errorMessage")[0].InnerText);
            }

            if (xml.DocumentElement.GetElementsByTagName("Document").Count > 0)
            {
                string base64EncodedFile = xml.DocumentElement.GetElementsByTagName("content")[0].InnerText;
                string contentType = xml.DocumentElement.GetElementsByTagName("contentType")[0].InnerText;
                docPath = i_DocId + "." + contentType;
                // Save the file on the server
                File.WriteAllBytes(HttpContext.Current.Server.MapPath("~/" + docPath), Convert.FromBase64String(base64EncodedFile));
            }

            return docPath;
        }

Usage Example

Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // When retrieveSignedFile.aspx is called by CSWA, it can be of the following reasons:
            // 1. An error was returned - in this case only, returnCode param will not be null
            // 3. A file was signed and is waiting to be 'pulled'

            string docId     = Request.QueryString["docId"];
            string sessionId = Request.QueryString["sessionId"];
            string retVal    = "-1";

            try
            {
                if (!string.IsNullOrEmpty(docId))
                {
                    retVal = Request.QueryString["returnCode"];
                    if (retVal != null && retVal != "0")
                    {
                        // An error was recieved
                        handleError(retVal, Request.QueryString["errorMessage"]);
                    }
                    else if (!string.IsNullOrEmpty(sessionId))
                    {
                        // A document was signed and needs to be handled
                        string fileName = Helper.pullDoc(docId, sessionId);

                        linkToDoc.InnerText     = fileName;
                        linkToDoc.HRef          = fileName;
                        LabelResultMessage.Text = "The document has been successfully signed";
                    }
                    else
                    {
                        // Empty Request (no sessionId parameter)
                        handleError(retVal, "Missing parameters");
                    }
                }
                else
                {
                    // Empty Request (no docId parameter)
                    handleError(retVal, "Missing parameters");
                }
            }
            catch (Exception ex)
            {
                handleError(retVal, ex.Message);
            }
        }