2013-10-01 52 views
0

我收到錯誤 無法加載模板。無法從TemplateReference(0)加載模板。錯誤:根級別的數據無效。行1,位置1.我得到c#和Docusign錯誤如何解決此錯誤

下面是我正在使用的代碼的簡化版本... 如果我不使用模板引用類型的代碼一切工作正常。但是,當我開始使用模板引用..沒有任何作品,我得到這個錯誤。任何人都有建議?

 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 = "[email protected]"; 
     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); 

回答

0

如果您使用的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(); 
    } 
+0

看起來我缺少的是TemplateLocation = DocuSignAPI.TemplateLocationCode.Server行, – Rico