Assemble Document
When it is time to assemble a document, you can call the AssembleDocument method of the HotDocs Cloud Services web service to assemble a document in one or more formats.
- Create an AnswersSource object, which contains the answers to be used in the assembled document. Typically, these answers come from a browser interview.
- Create a Template object, which indicates which template package to use for the assembly, as well as the name of the template within that package.
- Create an AssembleDocumentOptions object, which indicates which format and settings to use for the assembly.
- Call AssembleDocument. The following code sample illustrates how this can be done:
AssemblyResult result = null;
using (HotDocs.Core.Client.SvcClient client = new HotDocs.Core.Client.SvcClient(Settings.SubscriberID, Settings.SigningKey, Settings.CoreServicesUrl))
{
try
{
System.IO.MemoryStream answerStream = new MemoryStream(answers.Data);
HotDocs.Core.Client.PackageSource packageStreamProvider = new HotDocs.Core.Client.PackageSource(packageFileName);
HotDocs.Core.Client.Template template = new Template(packageID, templateName, packageStreamProvider);
HotDocs.Core.Client.AnswersSource answerStreamsProvider = new HotDocs.Core.Client.AnswersSource(answerStream, true);
HotDocs.Core.Client.AssembleDocumentOptions options = new AssembleDocumentOptions(format, settings);
result = client.AssembleDocument(template, answerStreamsProvider, options, Util.BillingRef);
}
catch (Exception ex)
{
throw ex;
}
}
return result;
- Inspect the AssemblyResult object that is returned to retrieve the assembled document(s).
To assemble a document using the web service directly
-
Call AssembleDocument. The following code sample illustrates how this can be done:
<code language="C#" title="Example">
AssemblyResult result = null;
using (HDCoreSvc.CoreClient client = new HDCoreSvc.CoreClient(Settings.WSEndpoint))
{
bool sendPackage = false;
int retries = 0;
DateTime timeStamp = DateTime.UtcNow;
while (result == null && retries < 2)
{
try
{
result = client.AssembleDocument(
Settings.SubscriberID,
packageID,
templateName,
answers == null ? null : new BinaryObject[] { answers },
format,
settings,
Util.BillingRef,
timeStamp,
sendPackage ? CreateBinaryObject(packageFileName) : null,
HotDocs.Core.HMAC.CalculateHMAC(Settings.SigningKey, timeStamp, Settings.SubscriberID, packageID, templateName, sendPackage.ToString(), Util.BillingRef, format, settings)
);
}
catch (FaultException<ExceptionDetail> ex)
{
switch (ex.Detail.Type)
{
case "HotDocs.Cloud.Storage.PackageNotFoundException"
// The package was not found on the server, so try again, this time sending the package
sendPackage = true;
retries++;
break;
default:
retries = 2; // This is an exception we don't know how to handle, so don't retry any more.
throw ex;
}
}
}
SafeCloseClient(client);
}
return result; - Inspect the AssemblyResult object that is returned to retrieve the assembled document(s).