SDK Example 7: Using Cloud Services with the HotDocs Open SDK

When using the HotDocs Open SDK in your application, you will need to create a HotDocs Service object to interact with the selected HotDocs Service. In the SDK Examples, this is a locally-installed instance of HotDocs Server. However, it is also possible to use HotDocs Cloud Service with the HotDocs Open SDK. To use this service instead of HotDocs Server, the service object must be created in a slightly different way. Full source code for this example is available at the bottom of the page.

To use Cloud Services with the HotDocs Open SDK, you must be a Cloud Services subscriber. If you are not a subscriber, please contact your HotDocs Sales representative for more information.

Example Source Code on GitHub

The SdkExample7CloudServices example project is available on GitHub, in the HotDocs-Samples repository.

What is Cloud Services?

HotDocs Cloud Services is a hosted document generation platform. It runs in Microsoft’s Azure cloud and provides state-of-the art data security and on-demand document generation in any modern browser. Subscribers to Cloud Services can use HotDocs content and take advantage of hosted interview and document assembly capabilities. For more information, see the Cloud Services help documentation.

1. Create a Visual Studio Project for the Cloud Services example

If you have not done so already, create a new Visual Studio Solution and Console Application project. Name it SdkExample7CloudServices. You will gradually add code to this project until you have a working example.

Adding the HotDocs Cloud Services DLLs to a Visual Studio Project

The steps to add a DLL to a Visual Studio project are outlined in Install the HotDocs Open SDK. To use HotDocs Cloud Services, you will use the HotDocs.Sdk.Cloud DLL instead of the HotDocs.Sdk.Server DLL.

Referencing the HotDocs Cloud Services DLLs

Before you start developing with the HotDocs Open SDK, you should have either referenced the HotDocs Open SDK DLLs in your solution or added the SDK project files to your solution. If you have not done this, see Install the HotDocs Open SDK for instructions.

Open your solution and navigate to the class you wish to edit. Add the following Using statements at the beginning of your class: 

Using HotDocs.Sdk;
Using HotDocs.Sdk.Server;
Using HotDocs.Sdk.Server.Cloud;
Using HotDocs.SDK.Server.Contracts;
Using Util = HotDocs.Sdk.Util;

In each new project you create, you should include the Using statements listed above. You are now ready to start using the HotDocs Cloud Services with the HotDocs Open SDK.

Creating the HotDocs Service

To use Cloud Services, you must first create a method that will create a HotDocs Service object that connects to Cloud Services. In the first SDK example, you created the following method for connecting to a local instance of HotDocs Server, CreateHotDocsService:

 

private static Services CreateHotDocsService()

{

const string tempDirectoryPath = @"C:\temp\";

var service = new Services(tempDirectoryPath);

return service;

}

 

With a few changes, the same method can be used to create a Cloud Service object.

 

private static Services CreateHotDocsService()

{

var service = new HotDocs.Sdk.Server.Cloud.Services(SubscriberId, SigningKey);

return service;

}

 

In this example, you use the HotDocs.Sdk.Server.Cloud namespace, rather than the HotDocs.Sdk.Server.Local namespace used in the previous examples. This use of Services also differs in that, instead of a temporary file path parameter, these are two parameters that supply identification information to Cloud Services:

  • SubscriberId (string) the Subscriber ID for your HotDocs Cloud Services account.
  • SigningKey (string) – the signing key associated with the Subscriber ID above.

The rest of the code in the SDK examples can be used exactly as before, without any further changes.

Source Code (C#)

 

using System;

using System.IO;

using HotDocs.Sdk;

using HotDocs.Sdk.Server;

using HotDocs.Sdk.Server.Cloud;

namespace SdkExample7CloudServices

{

    /// <summary>

    /// This demonstrates assembling a document from a template using HotDocs Cloud Services and assuming we already have answer XML.

    /// This examples uses the same code as Example 1. Only the CreateHotDocsService method has changed.

    /// </summary>

    internal class Example7

    {

        private static void Main(string[] args)

        {

            AssembleDocument();

        }

        private static void AssembleDocument()

        {

            var assembledDocumentResult = CreateAssembleDocumentResult();

            using (var fileStream = File.Create(@"C:\temp\output" + assembledDocumentResult.Document.FileExtension))

            {

                assembledDocumentResult.Document.Content.CopyTo(fileStream);

            }

        }

        private static AssembleDocumentResult CreateAssembleDocumentResult()

        {

            var template = CreateTemplate();

            var answers = GetAnswers();

            var assembleDocumentSettings = new AssembleDocumentSettings();

            var service = CreateHotDocsService();

            var assembledDocumentResult = service.AssembleDocument(template, answers, assembleDocumentSettings, "Example Assemble Document Log Text");

            return assembledDocumentResult;

        }

        private static Services CreateHotDocsService()

        {

            // You must change the 'ExampleSubscriberId' and 'ExampleSubscriberKey' values to your own HotDocs Cloud Services identification information.

            var service = new Services("ExampleSubscriberId", "ExampleSubscriberKey");

            return service;

        }

        private static StringReader GetAnswers()

        {

            return new StringReader(@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?><AnswerSet version=""1.1""><Answer name=""TextExample-t""><TextValue>Hello World</TextValue></Answer></AnswerSet >");

        }

        private static Template CreateTemplate()

        {

            const string packagePath = @"C:\temp\HelloWorld.hdpkg";

            var packageId = Guid.NewGuid().ToString();

            var templateLocation = new PackagePathTemplateLocation(packageId, packagePath);

            var template = new Template(templateLocation);

            return template;

        }

    }

}