Using the NintexFormsPublishExample sample

This topic looks at how to use the NintexFormsPublishExample code sample.

The NintexFormsPublishExample sample demonstrates how to use a Windows Communication Foundation (WCF) client channel and service proxy to invoke the Nintex Forms REST API methods and, depending on whether the client channel is connected to SharePoint 2010 or SharePoint 2013, use the appropriate SOAP service operation or REST method, respectively, to retrieve the appropriate form digest value during invocation.

Overview

The sample is a Visual Studio solution that consists of two projects:

Download the Source Code

The sample contains two project: the NintexFormsClient and an example console application. The console app uses the NintexFormsClient to connect to the GetFormXML, PublishXML, and DeleteXML endpoints. The sample will not run without being configured. For the steps on configuring the sample, see Building and running the sample.

Download source code

NintexFormsClient

The NintexFormsClient project is where the interaction with SharePoint and Nintex Forms is encapsulated. The NfClientContext class manages interaction between the NfRestService service and the PublishFormExample application. The class wraps the WCF service proxy class, FormsWcfServiceProxy, which in turn wraps the WCF client channel. The WCF client channel implements the IFormsWcfService interface, which defines the operation contracts for the DeleteForm, GetFormXml, and PublishFormXml methods.

The NfClientContext class supports both SharePoint 2010 and SharePoint 2013 form digest authentication, by using the FormDigestFactory class to instantiate, respectively, a FormDigest2010 or FormDigest2013 object and retrieve the appropriate form digest value for use in the FormsHeaderBehavior object. The FormsHeaderBehavior object is derived from the WebHttpBehavior class, and is added to the endpoint behaviors used by the FormsWcfServiceProxy class so that, when an operation is invoked from the service proxy, the appropriate form digest value is added to the request header.

PublishFormExample

The Program class uses the NfClientContext class to perform the following actions:

  1. Retrieve the form definition XML from the source environment (the combination of a SharePoint site and list specified in the sample), and then save the XML to a file for later use.

    The GetFormFromListAndSaveToFile method uses the GetFormXml method to retrieve the XML definition of a Nintex form from the specified SharePoint list and saves it to a file.

  2. Retrieve the form definition XML from the source environment, and then publish the form to the destination environment.

    The GetFormFromListAndPublishToList method uses the GetFormXml and PublishFormXml methods to retrieve the XML definition of a Nintex form from one specified SharePoint list and publishes the XML definition to another specified SharePoint list.

  3. Delete the form from the source environment.

    The DeleteFormFromList method uses the DeleteForm method to delete the Nintex form from the source environment.

  4. Retrieve the form definition XML from a file and then publish the form to the source environment.

    The GetFormFromFileAndPublishToList method retrieves the XML definition for a Nintex form from the file saved in step 1 and then uses the PublishFormXml method to publish the form to the source environment, restoring the form deleted in step 3.

Building and running the sample

Note: The sample can be successfully built, but will not successfully run, without performing the following procedure.

To run the sample, perform the following steps:

  1. Open the NintexFormsPublishExample Visual Studio solution in Visual Studio 2012 or a later version.

  2. Find each instance of the following text in the Program.cs file of the PublishFormExample project, and perform the action described in each matching comment.

    // TODO:
                        

    For example, the first line of code in the Program class defines the NetworkCredential instance that represents the credentials to use when invoking the REST API. That line of code is preceded by the following comments:

    // TODO: Set the NTLM credential information.
    // Ensure that the specified credentials have access to the SharePoint web URLs for both
    // the source and destination environments specified in the methods for this

    Follow the instructions and edit the code as needed to satisfy all of the requisite changes.

  3. Build the Visual Studio solution.

Related information

Migrate Forms with the Nintex Forms Web Service API

Web Service Reference