DownloadEnvelopeDocuments - C#

Last updated 2020-09-25 18:38:27 UTC

// DocumentNOW V2 DownloadEnvelopeDocuments example
// assuming we set the namespace on the service proxy to DocNow ...

// force TLS 1.2 if .net < 4.6
ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

Guid accountContextID = new Guid(<fromYourAccount>);
Guid envelopeId = new Guid(<fromSubmission>);
Guid authToken = new Guid(<fromSubmission>);

DocNow.EnvelopeServiceClient client = new DocNow.EnvelopeServiceClient("BasicHttpBinding_IEnvelopeService1");
DocNow.DownloadEnvelopeDocumentsRequest request = new DocNow.DownloadEnvelopeDocumentsRequest();
request.ContextIdentifier = accountContextID;
request.EnvelopeId = envelopeId;
request.AuthToken = authToken;

DocNow.DownloadEnvelopeDocumentsResult result = client.DownloadEnvelopeDocuments(request);

if(result.Exceptions != null)
    StringBuilder sb = new StringBuilder();
    foreach (DocNow.EnvelopeException exception in result.Exceptions)
        sb.AppendFormat("{0}{1} : {2}", Environment.NewLine, exception.Severity.ToString(), exception.Value);
    throw new Exception($"Errors occurred calling DownloadEnvelopeDocuments:{sb.ToString()}");
// if we had set: request.MergeCompletedDocuments = true;
// then we would check result.MergedDocument foreach(DocNow.EnvelopeDocument document in result.Documents) { Console.WriteLine($"{document.DocumentId}"); Console.WriteLine($"{document.Name}"); if(document.CompletedDocument != null) { byte[] filecontents = document.CompletedDocument.Data; File.WriteAllBytes($"c:\\temp\\{document.DocumentId}.pdf", filecontents); } } }

For .NET clients, you may initially receive an error when downloading a file with the following or similar message:

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element

To make this change, modify the following bindings to set an increased max message size, such as

<binding name="BasicHttpBinding_IEnvelopeService" messageEncoding="Mtom" maxReceivedMessageSize="2000000" maxBufferSize="2000000">
    <security mode="Transport" />
<binding name="BasicHttpBinding_IEnvelopeService1" maxReceivedMessageSize="2000000" maxBufferSize="2000000">
    <security mode="Transport" />