Asp.net mvc 在DotNet应用程序中使用DocuSign时出错

Asp.net mvc 在DotNet应用程序中使用DocuSign时出错,asp.net-mvc,docusignapi,Asp.net Mvc,Docusignapi,我正在我的应用程序中实现DocuSign功能来签署PDF。 我正在浏览以下链接: 我们可以在使用上述链接中提到的步骤时在PDF中添加签名,但在第二次调用相同的方法对新PDF进行签名时,我们会在CreateEnvelope行收到错误消息 错误响应:{errorCode:UNSPECIFIED_错误,消息: 输入字符串的格式不正确。} 它在创建信封时生成错误。在这条线上 EnvelopesSummary EnvelopesSummary=envelopesApi.CreateEnvelopeeAcc

我正在我的应用程序中实现DocuSign功能来签署PDF。 我正在浏览以下链接: 我们可以在使用上述链接中提到的步骤时在PDF中添加签名,但在第二次调用相同的方法对新PDF进行签名时,我们会在CreateEnvelope行收到错误消息

错误响应:{errorCode:UNSPECIFIED_错误,消息: 输入字符串的格式不正确。}

它在创建信封时生成错误。在这条线上

EnvelopesSummary EnvelopesSummary=envelopesApi.CreateEnvelopeeAccountId,envDef

下面是我使用的代码

static string userName = Utility.GetConfigValue("docSignUserName");
        static string password = Utility.GetConfigValue("docSignPassword");
        static string integratorKey = Utility.GetConfigValue("docSignIntegratorKey");
        static string baseURL = "";

        public static SignedPDF SignDocument(UserViewModel user, StateViewModel state, string signFilePath, string newFilePath, string controlSign)
        {
            PdfReader pdfReader = new PdfReader(signFilePath);
            PdfReader newpdfReader = new PdfReader(newFilePath);
            PdfStamper pdfStamper = new PdfStamper(newpdfReader, new FileStream(HttpContext.Current.Server.MapPath(Utility.GetConfigValue("StateTaxForms")) + "Test.pdf", FileMode.Create));
            AcroFields pdfFormFields = pdfStamper.AcroFields;
            IList<AcroFields.FieldPosition> fieldPositions = pdfFormFields.GetFieldPositions(controlSign);

            try
            {
                AcroFields.FieldPosition fieldPosition = fieldPositions[0];

                // Enter recipient (signer) name and email address
                string recipientName = user.FirstName + " " + user.LastName;
                string recipientEmail = user.Email;

                // instantiate api client with appropriate environment (for production change to www.docusign.net/restapi)
                string basePath = Utility.GetConfigValue("docSignInstantiateClient");

                // instantiate a new api client
                ApiClient apiClient = new ApiClient(basePath);

                // set client in global config so we don't need to pass it to each API object
                Configuration.Default.ApiClient = apiClient;

                string authHeader = "{\"Username\":\"" + userName + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
                Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

                // we will retrieve this from the login() results
                string accountId = null;

                // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
                AuthenticationApi authApi = new AuthenticationApi();
                LoginInformation loginInfo = authApi.Login();

                // user might be a member of multiple accounts
                accountId = loginInfo.LoginAccounts[0].AccountId;

                // Read a file from disk to use as a document
                byte[] fileBytes = File.ReadAllBytes(signFilePath);

                EnvelopeDefinition envDef = new EnvelopeDefinition();
                envDef.EmailSubject = "Please sign this document";

                // Add a document to the envelope
                Document doc = new Document();
                doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
                doc.Name = "SignedFile.pdf";
                doc.DocumentId = "1";

                envDef.Documents = new List<Document>();
                envDef.Documents.Add(doc);

                // Add a recipient to sign the documeent
                Signer signer = new Signer();
                signer.Name = recipientName;
                signer.Email = recipientEmail;
                signer.RecipientId = "1";

                // must set |clientUserId| to embed the recipient
                signer.ClientUserId = "1234";

                // Create a |SignHere| tab somewhere on the document for the recipient to sign
                signer.Tabs = new Tabs();
                signer.Tabs.SignHereTabs = new List<SignHere>();
                SignHere signHere = new SignHere();

                var height = pdfReader.GetPageSize(1).Height;
                signHere.DocumentId = "1";
                signHere.RecipientId = "1";
                signHere.PageNumber = Convert.ToInt32(fieldPosition.page).ToString();
                signHere.XPosition = Convert.ToInt32(fieldPosition.position.Left).ToString();
                if (state.Abbreviation == "DC" && controlSign != "Signature of Employee")
                {
                    signHere.YPosition = (height - Convert.ToInt32(fieldPosition.position.Top - 5)).ToString();
                }
                else
                {
                    signHere.YPosition = (height - Convert.ToInt32(fieldPosition.position.Top + 35)).ToString();
                }
                if (state.Abbreviation == "NC" && controlSign != "Signature of Employee")
                {
                    signHere.YPosition = (height - Convert.ToInt32(fieldPosition.position.Top + 25)).ToString();
                }
                signer.Tabs.SignHereTabs.Add(signHere);

                envDef.Recipients = new Recipients();
                envDef.Recipients.Signers = new List<Signer>();
                envDef.Recipients.Signers.Add(signer);

                // set envelope status to "sent" to immediately send the signature request
                envDef.Status = "sent";

                // Use the EnvelopesApi to create and send the signature request
                EnvelopesApi envelopesApi = new EnvelopesApi();
                EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);

                RecipientViewRequest viewOptions = new RecipientViewRequest()
                {
                    ReturnUrl = Utility.GetConfigValue("docSignReturnURL"),
                    ClientUserId = "1234",  // must match clientUserId set in step #2!
                    AuthenticationMethod = "email",
                    UserName = recipientName,
                    Email = recipientEmail
                };

                // create the recipient view (aka signing URL)
                ViewUrl recipientView = envelopesApi.CreateRecipientView(accountId, envelopeSummary.EnvelopeId, viewOptions);

                // Start the embedded signing session!
                //var value = System.Diagnostics.Process.Start(recipientView.Url);
                SignedPDF signedPDF = new SignedPDF();
                signedPDF.URL = recipientView.Url;
                signedPDF.EnvelopeID = envelopeSummary.EnvelopeId;
                return signedPDF;
            }
            catch (Exception ex)
            {
                throw new PDFSignException(ErrorConstants.THERE_WAS_AN_ERROR_WHILE_SIGNING_PDF);
            }
            finally
            {
                pdfStamper.Close();
                pdfReader.Close();
            }
        }
由于长度不受支持,我们已删除base 64字符串。

请确保正确传递signHere.XPosition和signHere.YPosition值

以下语句的计算结果可能为十进制值。确保它是一个整数

signHere.YPosition = (height - Convert.ToInt32(fieldPosition.position.Top + 25)).ToString();
故障排除步骤
请运行EnvelopedDefinition.ToJson Sdk并确保发布到DocuSign api的最终Json是正确的。

请添加您的代码。请澄清您的具体问题或添加其他详细信息,以突出显示您所需的内容。正如目前所写的,很难准确地说出你在问什么。请参阅页面以获取澄清此问题的帮助。XPosition和YPosition的最终值是什么?能否在envelopesApi.CreateEnvelope语句之前运行此envDef.ToJson并将json发布到问题中。嗨,团队,我找到了解决方案。实际上,在我们的例子中,Y位置是作为十进制值。我们已将十进制数四舍五入,现在运行良好。
signHere.YPosition = (height - Convert.ToInt32(fieldPosition.position.Top + 25)).ToString();