LoanCo Sample App Now Available in C#

LoanCo is a sample loan app for a fictitious company that shows some common ways an application might interact with the DocuSign eSignature API. It shows three separate examples, each increasing in features and functionality:

  • Personal Loan – Basic embedded signing with a single signer on a single document
  • Auto Loan – Multiple signers with multiple documents, using a template and calculated tabs
  • Sailboat Loan – Sign and initial tabs with optional signers, custom branding, specifying routing order, and complex document visibility

Not only can you tryout the functionality of each use-case in the live LoanCo sample app, but you can also download the code on GitHub to try for yourself or to act as a starting point for your own applications and integrations. We started by making the sample app code available in Node.js, but due to overwhelming demand, we just released it in C# as a Visual Studio 2017 solution too.

The LoanCo C# Approach

The design goal was to port the Node.js LoanCo sample app to C#, but not to increase the complexity by forcing you to install and configure a Windows web server with Internet Information Services (IIS). Node.js make serving web pages and responding to HTTP requests very simple without additional configuration. Additionally, if we make updates to the Node.js LoanCo sample, these changes can be easily migrated into the C# version (or other versions we may release). Therefore, we decided to keep the Node.js web code framework and only port to C# the code that calls the DocuSign API.

The downside to this approach is that there is no native way to make C# (.NET) calls directly from Node.js, so we implemented the Edge.js library (available as a NuGet package within Visual Studio 2017). Edge.js does the hard work of marshalling calls between Node.js and C#, which enabled us to focus solely on the C# porting.

The Visual Studio LoanCo Solution is comprised of two separate projects:

  1. DocuSign CSharp LoanCo –C# project that can be run in one of two modes:

    • Class library – Generates the DocuSign.dll library that will be called by the Node.js project through the Edge.js library. This is useful when running or debugging the Node.js web UI.
    • Console Application – Useful for debugging the C# code, but will not invoke the Node.js web UI.
  1. Sample-app-loanco-nodejs-master – Node.js project that started from the GitHub LoanCo source. Only these files from the routes folder were modified to remove the Node.js API-specific code:

    • loan-personal.js
    • loan-auto.js
    • loan-sailboat.js

Getting Started

To get started, follow these simple steps:

    1. Install Node.js version 6.9.4 on a Windows computer. As of this writing, versions greater than 6.9.4 are not supported on Edge.js.
    2. Open a node.js command prompt and install edge with this command-line
      npm install edge
    3. Open or unzip the LoanCo C# Visual Studio solution on GitHub.
    4. Ensure the NuGet packages are loaded automatically. If not, you may need to install them individually. These are the packages in the solution:
    5. Edit the .env file in the root folder of the Node.js project to configure properties used by the node.js application. The entries you need to change are listed as <replace>:
            EMPLOYEE_NAME=Internal LoanCo Account

    1. Edit the app.config file in the root folder of the C# project to configure properties used by the C# application. The entries you need to change are shown with a <replace> tag:
                <add key="DOCUSIGN_ENVIRONMENT" value="demo" />
                <add key="DOCUSIGN_USERNAME" value="<replace>" />
                <add key="DOCUSIGN_PASSWORD" value="<replace>" />
                <add key="DOCUSIGN_IK" value="<replace>" />
                <add key="EMPLOYEE_EMAIL" value="<replace>" />
                <add key="EMPLOYEE_NAME" value="Internal LoanCo Account" />
                <add key="LOCAL_RETURN_URL" value="http://localhost:3801/" />
                <add key="AUTOLOAN_TEMPLATEID" value="<replace>" />
                <add key="BRAND_ID" value="f157069c-3828-4073-a298-0bf5749b27bb" />
                <add key="GOOGLE_MAPS_API_KEY" value="AIzaSyD1-3_ag-DVGsvLuHWfx-gOE4-F2y-rskk" />
                <add key="GOOGLE_ANALYTICS" value="UA-39550292-1" />
                <add key="DEFAULT_EMAIL" value="<replace>" />
                <add key="FORCE_HTTPS" value="0" />
                <add key="ClientSettingsProvider.ServiceUri" value="" />


Q: When compiling for the first time, I’m getting a “Cannot find module ‘edge’ error.

A: Open a node.js command prompt and run npm install edge

Running the Solution

To run the LoanCo Visual Studio Solution, simply press F5. it is set by default to build the C# project as a Windows Class library (see description above) and then start the Node.js web server. If this doesn't work ensure you have these settings:

  1. Set sample-app-loanco-nodejs-master.njsproj project as StartUp project.
  2. Right-click the DocuSign CSharp LoanCo project and select properties.
  3. Ensure Output type is Class Library.

Running the solution using Node.js as the web server won't break in your C# code when you set breakpoints, but you can debug your code using message boxes. When the Node.js web server is running, open a browser and navigate to http://localhost:3801. Here's what that looks like:

If you want to set breakpoints in your C# code and step through the C# code, you run the project as a Windows Console application (see description above) with these settings:

  1. Set DocuSign CSharp LoanCo project as StartUp project.
  2. Right-click the DocuSign CSharp LoanCo project and select properties.
  3. Ensure Output type is Console Application.
  4. Set Startup Object as DocuSign.Program.

Running the solution as a Windows Console application won't invoke the Node.js web server, so you run each use-case in your C# code from Main(). If you navigate to this function, you'll see prototypes for each of the three use-cases (loan types) to easily run them. Here's what that looks like:

We'd love to hear your feedback on the C# app. Please comment on this blog post. Enjoy!

Additional Resources

Get more information about DocuSign Payments and stay up-to-date with DocuSign developer news and information by visiting these additional resources:

Tony Mann
Tony Mann
Director of Developer Content