您的位置:首页 > 运维架构

转:How to submit rows of a repeating table in InfoPath to a web service? 如何将重复表中的记录传给Web Service ?

2009-07-31 19:33 531 查看
关键点及注意事项:

1, 注意其中红色字体部分,namespace 必须和对应的 InfoPath Form 中一致,其中一个办法就是在 InfoPath Form 设计阶段查看Group 对应的属性,可直接取得其 namespace;

2, 在 RepeatingTable class 定义中,必须确保其中两个Group 的名称和 InfoPath Form 中对应的Group 名称完全一致,否则将无法成功调用此 class;

3, 除了 Group 的名称要一致外,还必须确保在Class 中定义的 Field 的名称也必须和 Repeating Table 包括的每个数据列的名称完全一致,否则也将无法保存成功;

4, 如果调用Web Service 时出现错误,如 NullException 等,请先检查是否以上3点正确。

转: http://www.bizsupportonline.net/infopath2007/how-to-submit-repeating-table-infopath-web-service.htm

Learn how you can create a .NET web service that accepts data from the rows of a repeating table on an InfoPath form.

Problem

You have a repeating table on an InfoPath form and you want to submit the data from all of the rows in the repeating table to a .NET web service.

Solution

Create a .NET web service that accepts a parameter that can be serialized as an array of XML elements.

Discussion

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:

[System.Xml.Serialization.XmlRootAttribute(
Namespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-02-23T05:14:24",
IsNullable = false)]
public class RepeatingTable
{
[System.Xml.Serialization.XmlArray("group1")]
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:

[WebMethod]
public void SubmitRepeatingTable(
RepeatingTable myRepTable)
{
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐