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.
The sample is a Visual Studio solution that consists of two projects:
A class library that implements the WCF client channel and client proxy used for the NfRestService service, with an IClientMessageInspector implementation that manages form digest authentication for both SharePoint 2010 (with SOAP) and SharePoint 2013 (with REST).
A console application that uses NintexFormsClient to demonstrate how to retrieve, publish, and delete forms using the NfRestService service.
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
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.
The Program class uses the NfClientContext class to perform the following actions:
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.
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.
Delete the form from the source environment.
The DeleteFormFromList method uses the DeleteForm method to delete the Nintex form from the source environment.
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.
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:
Open the NintexFormsPublishExample Visual Studio solution in Visual Studio 2012 or a later version.
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.
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.
Build the Visual Studio solution.
Migrate Forms with the Nintex Forms Web Service API
Web Service Reference