我收到 c# 和文档错误如何解决此错误

本文关键字:错误 解决 何解决 文档 | 更新日期: 2023-09-27 18:33:20

>我收到错误无法加载模板。无法从模板引用 (0) 加载模板。错误:根级别的数据无效。第 1 行,位置 1。

下面是我正在使用的代码的简化版本...如果我不使用代码的模板引用类型,一切正常。 但是当我开始使用模板引用时..没有任何效果,我收到此错误。 有人有建议吗?

      TemplateReference _tempRef = new TemplateReference();
      TemplateReference[] _tempRefs = new TemplateReference[] { };
      TemplateReferenceRoleAssignment[] _roleAssignmentArray = new TemplateReferenceRoleAssignment[] { };
      Recipient[] _recipientsArray = new Recipient[] { };

      EnvelopeInformation envelope = new EnvelopeInformation();
        Recipient recipient = new Recipient();
        recipient.ID = "1";
        recipient.Email = "someemail@somewhere.com";
        recipient.UserName = "Some Person";
        recipient.Type = RecipientTypeCode.Signer;
        recipient.RequireIDLookup = false;
        Array.Resize(ref _roleAssignmentArray, 1);
        Array.Resize(ref _recipientsArray, 1);

        _recipientsArray[0] = recipient;
        var saRoleAssignment = new TemplateReferenceRoleAssignment
        {
            RecipientID = "1",
            RoleName = "SA"
        };
        _roleAssignmentArray[0] = saRoleAssignment;
        var reference = new Docusign.TemplateReference();
        reference.Template = "49C0BE2B-48F7-4F38-B44A-19EB8E6A1A38";
        reference.Document = new Docusign.Document();
        reference.Document.PDFBytes = new byte[0];
        reference.Document.ID = Convert.ToString(1);
        reference.Document.Name = "please work";
        reference.RoleAssignments = _roleAssignmentArray;
        Array.Resize(ref _tempRefs, 1);
        _tempRefs[1 - 1] = reference;
        //.NET
        //.NET
        envelope.AccountId = "accountID";
        envelope.Subject = "Sample Application";
        envelope.EmailBlurb = "You can add a personal message here.";

        APIServiceSoapClient apiService = new APIServiceSoapClient();
        apiService.ClientCredentials.UserName.UserName = "userhere";
        apiService.ClientCredentials.UserName.Password = "pass";
        var status = apiService.CreateEnvelopeFromTemplates(_tempRefs, _recipientsArray, envelope, true);

我收到 c# 和文档错误如何解决此错误

如果您使用的是DocuSign的SOAP api而不是REST,那么您绝对应该熟悉GitHub上的SOAP SDK:

https://github.com/docusign/DocuSign-eSignature-SDK

有一个 MS.NET (C#) 版本,其中包含开箱即用的示例代码,您只需输入 api 凭据。 我建议你使用它作为你的项目基础,特别是因为它最近更新了。

由于您尚未确定错误源于哪一行,因此调试起来有点困难,但是如果您查看 SDK 中的SendTemplate.aspx.cs,您将看到模板引用是这样实例化的:

// Construct the template reference
var templateReference = new DocuSignAPI.TemplateReference
{
    TemplateLocation = DocuSignAPI.TemplateLocationCode.Server,
    Template = TemplateTable.Value,
    RoleAssignments = CreateFinalRoleAssignments(recipients)
};

其中CreateFinalRoleAssignments()定义为:

protected DocuSignAPI.TemplateReferenceRoleAssignment[] CreateFinalRoleAssignments(DocuSignAPI.Recipient[] recipients)
    {
        // Match up all the recipients to the roles on the template
        return recipients.Select(recipient => new DocuSignAPI.TemplateReferenceRoleAssignment
            {
                RecipientID = recipient.ID, RoleName = recipient.RoleName
            }).ToArray();
    }