0

我收到错误无法加载模板。无法从 TemplateReference(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);
4

1 回答 1

0

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

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

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

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

// 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();
    }
于 2013-10-01T05:57:20.753 回答