How to submit rows of a repeating table in InfoPath to a web service
Learn how you can create a .NET web service that accepts data from the rows of a repeating table on an InfoPath form.
You have an InfoPath repeating table on a form and you want to submit the data from all of the rows in the repeating table to a .NET web service.
Create a .NET web service that accepts a parameter that can be serialized as an array of XML elements.
You can achieve this functionality as follows:
- In InfoPath, create a new form template.
Add a Repeating Table control with 3 columns to the InfoPath form template. By default the repeating table will contain a non-repeating group node named group1, a repeating group node named group2, and 3 fields named field1, field2, and field3.
Figure 1. The default structure of a repeating table in InfoPath.
The repeating table shown above can be seen as an array of group2 nodes. This logic will be used by the web service to accept the XML data of the repeating table that is passed from the InfoPath form, and serialize this XML into an array of group2 items.
- In Visual Studio 2005, create a new Web Site project.
- Select the ASP.NET Web Service Visual Studio template, and name the web service SubmitRepeatingTableInfoPath.
- Add a new Class to the App_Code folder and name it RepeatingTable.
Add the following code to the RepeatingTable class:
Namespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-02-23T05:14:24",
IsNullable = false)]
public class RepeatingTable
public group2 rows;
public class group2
public string field1;
public string field2;
public string field3;
Note: You must replace the Namespace parameter of XmlRootAttribute with the namespace for your own InfoPath form template. To find this namespace, in InfoPath, on the File menu, click Save As Source Files, and select a folder where to extract the files contained in the form template. Go to the folder where you extracted the files, open the sampledata.xml file in Notepad, copy the namespace for the my namespace prefix and paste it into the class file in Visual Studio.
Delete the HelloWorld web method that Visual Studio adds by default to web service projects and add the following SubmitRepeatingTable web method to the web service:
public void SubmitRepeatingTable(
for (int i = 0; i < myRepTable.rows.Length; i++)
string field1 = myRepTable.rows[i].field1;
string field2 = myRepTable.rows[i].field2;
string field3 = myRepTable.rows[i].field3;
- In InfoPath, on the Tools menu, click Data Connections.
- On the Data Connections dialog box, click Add.
- On the Data Connection Wizard, select Create a new connection to, select Submit data, and click Next.
- On the Data Connection Wizard, select To a Web service, and click Next.
- On the Data Connection Wizard, type in the location for your web service, and click Next.
- On the Data Connection Wizard, select SubmitRepeatingTable from the Select an operation list, and click Next.
- On the Data Connection Wizard, click the button behind the Field or group field.
- On the Select a Field or Group dialog box, expand the nodes, select the group1 node, and click OK.
On the Data Connection Wizard, select XML subtree, including selected element from the Include drop-down list box, and click Next.
Figure 2. Data Connection Wizard in InfoPath to select the repeating table node to submit to the web service.
- On the Data Connection Wizard, click Finish.
- On the Data Connections dialog box, click Close.
- On the Tools menu, click Submit Options.
- On the Submit Options dialog box, select Allow users to submit this form, select Web service from the Send form data to a single destination drop-down list box, select the web service submit data connection you created from the Choose a data connection for submit drop-down list box, and click OK.
You should now be able to preview the InfoPath form, enter data in the repeating table, and click the Submit button to submit the data of the repeating table to the web service.
Related InfoPath Articles:
- How to submit data from an InfoPath form to a MySQL database using a Web Service
- How to submit the rows of a repeating table in InfoPath to a SharePoint list
- 5 Ways to submit an InfoPath form to a SharePoint list
- Submit an InfoPath form to a web service and then retrieve return values
- SharePoint Designer 2013 workflow to loop through InfoPath repeating table
Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.