public static void Main() { var authString = $"<DocuSignCredentials><Username>{_userName}</Username><Password>{_password}</Password><IntegratorKey>{_apiKey}</IntegratorKey></DocuSignCredentials>"; var client = new DSAPIServiceSoapClient(); using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty(); httpRequestProperty.Headers.Add("X-DocuSign-Authentication", authString); OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty; EnvelopeStatus status = client.RequestStatusEx(_envelopeId); Console.WriteLine($"Envelope ID: {_envelopeId}"); Console.WriteLine("Subject: " + status.Subject); // RequestEnvelope Method //var envelope = client.RequestEnvelope(_envelopeId, false); // RequestEnvelopeV2 Method var requestOptions = new RequestEnvelopeV2Options() { IncludeAC = false, IncludeAnchorTabLocations = true, IncludeDocumentBytes = false }; var envelopeV2 = client.RequestEnvelopeV2(_envelopeId, requestOptions); if (envelopeV2.Recipients != null && envelopeV2.Recipients.Any()) { var index = 1; Console.WriteLine($"{Environment.NewLine}Recipients:{Environment.NewLine}"); foreach (var rec in envelopeV2.Recipients) { Console.WriteLine($"{index++}. {rec.UserName} <{rec.Email}>"); } } if (envelopeV2.Tabs != null && envelopeV2.Tabs.Any()) { var index = 1; Console.WriteLine($"{Environment.NewLine}Tab data:{Environment.NewLine}"); foreach (var tab in envelopeV2.Tabs) { var recipient = envelopeV2.Recipients.FirstOrDefault(r => r.ID == tab.RecipientID); Console.WriteLine($"{index++}: ({recipient?.RoleName ?? "[no role]"}/{recipient?.UserName}) {tab.TabLabel}: {tab.Value}"); } } else { Console.WriteLine($"{Environment.NewLine}No tab data found."); } Console.WriteLine($"{Environment.NewLine}Done."); Console.ReadKey(); } }
public static FileData GetCertificate(string envelopeId, [IgnoreMappingDefault] DocusignCredentials overrideCredentials = null) { IDocusignCreds creds = overrideCredentials as IDocusignCreds ?? DSServiceClientFactory.DsSettings; DSAPIServiceSoapClient dsClient = DSServiceClientFactory.GetDsClient(creds); using (OperationContextScope scope = new OperationContextScope(dsClient.InnerChannel)) { OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = DSServiceClientFactory.GetAuthHeaderRequestProperty(creds); var documentsPDFs = dsClient.RequestCertificate(envelopeId); if (documentsPDFs == null || documentsPDFs.DocumentPDF == null || documentsPDFs.DocumentPDF.Length == 0) { return(null); } return(new FileData($"{documentsPDFs.DocumentPDF[0].Name}.pdf", documentsPDFs.DocumentPDF[0].PDFBytes)); } }
public static void AuthCopyFlow(string envelopeId) { //Configure these variables for your environment string userName = ""; string password = ""; string integratorKey = ""; string accountId = ""; //Use a GUID example db7f5b2a-xxxx-xxxx-xxxx-a815685a63eb //OAuth is not yet supported by DocuSign SOAP API //Authentication can be either WS-Security UsernameToken or Legacy custom header authentication, //although some development stacks may not provide adequate support for WS-Security standards. String auth = "<DocuSignCredentials><Username>" + userName + "</Username><Password>" + password + "</Password><IntegratorKey>" + integratorKey + "</IntegratorKey></DocuSignCredentials>"; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; DSAPIServiceSoapClient client = new DSAPIServiceSoapClient(); using (OperationContextScope scope = new System.ServiceModel.OperationContextScope(client.InnerChannel)) { HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty(); httpRequestProperty.Headers.Add("X-DocuSign-Authentication", auth); OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty; if (envelopeId.Trim().Length != 36) { Console.WriteLine("Error: EnvelopeId should be 36 characters. Current is " + envelopeId.Trim().Length.ToString()); Console.ReadLine(); return; } try { AuthoritativeCopyExportDocuments docs = client.ExportAuthoritativeCopy(envelopeId); //Concatenate the byte arrays of the returned encrypted documents var s = new MemoryStream(); List <string> encryptedFiles = new List <string>(); for (int i = 0; i < docs.Count; i++) { byte[] docPDF = docs.DocumentPDF[i].PDFBytes; s.Write(docPDF, 0, docPDF.Length); //write encrypted file to use later encryptedFiles.Add(@"c:\temp\authcopy\Testdoc.dat" + i.ToString()); File.WriteAllBytes(@"c:\temp\authcopy\Testdoc.dat" + i.ToString(), docPDF); } //Write the concatenated memory stream to the concatenatedByteArray var concatenatedByteArray = s.ToArray(); int size = concatenatedByteArray.Length; //Create a new fixed byte array required to hash byte[] data = new byte[size]; data = concatenatedByteArray; System.Security.Cryptography.SHA1 sha = new SHA1CryptoServiceProvider(); byte[] computedHash; computedHash = sha.ComputeHash(data); AuthoritativeCopyExportStatus status = client.AcknowledgeAuthoritativeCopyExport(envelopeId.Trim(), docs.TransactionId, computedHash); string key = status.ExportKey; Console.WriteLine("Status = " + status.AuthoritativeCopyExportSuccess + "Key = " + key); // loop writing decrypted docs to files for (int i = 0; i < docs.Count; i++) { //Create an empty target file string decryptedFilename = @"c:\temp\authcopy\" + docs.DocumentPDF[i].Name; if (decryptedFilename == @"c:\temp\authcopy\Summary") { decryptedFilename = @"c:\temp\authcopy\Summary.pdf"; } File.Create(decryptedFilename).Dispose(); //Decrypte the file using the key that was returned from AcknowledgeAuthoritativeCopyExport() try { Decrypt(status.ExportKey, encryptedFiles[i], decryptedFilename); Console.WriteLine("Success: new file " + decryptedFilename); } catch (Exception ex) { Console.WriteLine("Decrypt and file write failed."); Console.WriteLine(ex.Message); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.ReadLine(); }