5

I am working on a Adobe Echosign demo C# winforms application. My code is a direct copy of their command line code (with modifications), however, my code returns an error after it transmits the data.

This is the command line code from EchoSign that works

public static void sendDocument(string apiKey, string fileName, string formFieldLayerTemplateKey, string recipient)
{
    FileStream file = getTestPdfFile(fileName);
    secure.echosign.com.FileInfo[] fileInfos = new secure.echosign.com.FileInfo[1];
    fileInfos[0] = new secure.echosign.com.FileInfo(fileName, null, file);
    SenderInfo senderInfo = null;
    string[] recipients = new string[1];
    recipients[0] = recipient;
    DocumentCreationInfo documentInfo = new DocumentCreationInfo(
        recipients,
        testPrefix + Path.GetFileName(file.Name),
        testMessage,
        fileInfos,
        SignatureType.ESIGN,
        SignatureFlow.SENDER_SIGNATURE_NOT_REQUIRED
    );
    if (formFieldLayerTemplateKey != null)
    {
        secure.echosign.com.FileInfo[] formFieldLayerTemplates = new secure.echosign.com.FileInfo[1];
        formFieldLayerTemplates[0] = new secure.echosign.com.FileInfo(formFieldLayerTemplateKey);
        documentInfo.formFieldLayerTemplates = formFieldLayerTemplates;
    }
    DocumentKey[] documentKeys;
    documentKeys = ES.sendDocument(apiKey, senderInfo, documentInfo);
    Console.WriteLine("Document key is: " + documentKeys[0].documentKey);
}

This is my code block that returns an error from their system:

public static void sendDocument(string apiKey, string fileName, string formFieldLayerTemplateKey, string recipient)
{
    try
    {
        SenderInfo senderInfo = new SenderInfo();
        senderInfo = null;

        FileStream FileToSign = getTestPdfFile(fileName);
        byte[] bytes = System.IO.File.ReadAllBytes("C:\\PROJECTS\\TestFile.pdf");


        secure.echosign.com.FileInfo[] fileInfos = new secure.echosign.com.FileInfo[1];
        fileInfos[0] = new EchoSignTest.secure.echosign.com.FileInfo();
        fileInfos[0].fileName = fileName;
        fileInfos[0].mimeType = null;
        fileInfos[0].file = bytes;

        RecipientInfo[] docRecipient = new RecipientInfo[1];
        docRecipient[0] = new RecipientInfo();
        docRecipient[0].email = recipient;

        DocumentCreationInfo documentInfo = new DocumentCreationInfo();
        documentInfo.recipients = docRecipient;
        documentInfo.name = testPrefix + Path.GetFileName(FileToSign.Name);
        documentInfo.message = testMessage;
        documentInfo.fileInfos = fileInfos;
        documentInfo.signatureType = SignatureType.ESIGN;
        documentInfo.signatureFlow = SignatureFlow.SENDER_SIGNATURE_NOT_REQUIRED;

        if (formFieldLayerTemplateKey != null)
        {
            secure.echosign.com.FileInfo[] formFieldLayerTemplates = new secure.echosign.com.FileInfo[1];

            formFieldLayerTemplates[0] = new secure.echosign.com.FileInfo();
            formFieldLayerTemplates[0].formKey = formFieldLayerTemplateKey;
            documentInfo.formFieldLayerTemplates = formFieldLayerTemplates;
        }

        EchoSignDocumentService19PortTypeClient ES = new EchoSignDocumentService19PortTypeClient();
        DocumentKey[] documentKeys = new DocumentKey[1];

        documentKeys = ES.sendDocument(apiKey, senderInfo, documentInfo);
        Console.WriteLine("Document key is: " + documentKeys[0].documentKey);
    }
    catch (NullReferenceException ex)
    {
        string errMessage = ex.Message;
    }

    catch (Exception ex)
    {
        string errMessage = ex.Message;
    }
}  

What is different between the two code blocks? The error may reside in the FileInfo[] or DocumentCreationInfo() blocks. I am perhaps not creating the objects as the system requires.

Any suggestions are appreciated.

leppie
  • 109,129
  • 16
  • 185
  • 292
user3929962
  • 517
  • 3
  • 6
  • 23
  • 3
    Well, the obvious difference is that the second one is wrapped in a try/catch block that is squelching the error and preventing you from debugging the problem. – Cody Gray Aug 22 '14 at 16:05
  • I walk through the code the code does get to the sendDocument line without any errors. – user3929962 Aug 22 '14 at 16:07
  • 1
    Use a debugger to see what the value of `apiKey`,`senderInfo`, and `documentInfo` is in your console app, and then compare it to the values you get in your winforms app. They are most likely different. – Elias Aug 22 '14 at 17:03
  • I double checked and had two of my peers check as well... the values are the same – user3929962 Aug 22 '14 at 17:14
  • and I just got done checking the values again.... – user3929962 Aug 22 '14 at 17:38
  • You are creating your fileInfos[0] object using a different overload of the FileInfo constructor in the winforms example. Try creating that object in the same way in both. – Jason Aug 22 '14 at 17:42
  • @Jason when I try doing that, I get an error "'.secure.echosign.com.FileInfo' does not contain a constructor that takes 3 argument" – user3929962 Aug 22 '14 at 17:44
  • I see. You are using a different object to create the FileInfo in the second example. EchoSignTest vs secure. Is that another class you have defined somewhere? – Jason Aug 22 '14 at 17:47
  • EchoSignTest is the namespace for the WSDL I am using. The vendor is using the namespace secure. We are both using the same WSDL object – user3929962 Aug 22 '14 at 17:49
  • If they have different constructors, then they have be different WSDL's as one defines the FileInfo constructor that takes 3 arguments and one does not. – Jason Aug 22 '14 at 17:53
  • Much as I totally agree with your comment, we are both using the same WSDL version. I confirmed that with the vendor. – user3929962 Aug 22 '14 at 17:54
  • The ES.sendDocument call completes OK? If so, maybe there is nothing wrong with the "working parts" of the code at all... Perhaps the context in which the WinForms app is running doesn't have a valid output console. Have you tried using Debug.WriteLine instead of Console.WriteLine in the forms version? – Zenilogix Sep 01 '14 at 16:13

1 Answers1

1

The error seems to be the direct assignment of the bytes of the document you read to the fileInfos[0].file variable. In the documentation for FileInfo it states that the file parameter has to be the raw file content, encoded using base64, but you assign the raw file content without encoding it. When the constructor is called with a file stream like in your first example (the command-line one), the constructor seems to handle this automatically. You could try to change these lines in your Winforms example:

    FileStream FileToSign = getTestPdfFile(fileName);
    byte[] bytes = System.IO.File.ReadAllBytes("C:\\PROJECTS\\TestFile.pdf");


    secure.echosign.com.FileInfo[] fileInfos = new secure.echosign.com.FileInfo[1];
    fileInfos[0] = new EchoSignTest.secure.echosign.com.FileInfo();
    fileInfos[0].fileName = fileName;
    fileInfos[0].mimeType = null;
    fileInfos[0].file = bytes;

into this code and try if this works:

    FileStream FileToSign = getTestPdfFile(fileName);


    secure.echosign.com.FileInfo[] fileInfos = new secure.echosign.com.FileInfo[1];
    fileInfos[0] = new secure.echosign.com.FileInfo(fileName, null, FileToSign);

You should use the provided constructors instead of direct assignment to make sure all variables/parameters are handled properly.

The error you told about in your comments about the constructor that doesn't take 3 arguments could be a result of the EchoSignTest. prefix before your constructor call as it seems this is your own program's namespace and not the right namespace of the provided API.