在Infopath 2010中调用Web Service

刚刚和同事讨论了一个关于在InfoPath中调用Web Service的问题。

需求: 我需要在InfoPath表单中通过输入用户名来获得用户的其他信息,例如:部门, 上级等等。 并且通过无代码的方式实现。

clip_image002

环境: SharePoint Server 2010, InfoPath 2010.

技术:

1. 在SharePoint Server 2010 中有一个 “User Profile Service Web service” 可以用来调用用户数据;

2. Infopath中可以添加 数据来接来读取外部的数据。

步骤:

1. 创建一个空的InfoPath 2010表单;

2. 添加两个字段(字符串类型),然后把基于字段的控件添加到InfoPath表单上;

3. 添加一个按钮;

4. 添加数据连接;

clip_image004

5. 输入 User Profile Web Service的地址 http://servername/_vti_bin/userprofileservice.asmx

clip_image006

6. 选择 “GetUserPropertyByAccountName” 方法

7. 有两个参数需要输入: “accountName” and “propertyName”. 我们暂时只为“propertyName” 字段指定一个默认值“Department”

clip_image008

8. 完成。

 

到现在为止,完成所有的步骤了吗?没有!我们还没有把Web Service的参数和InfoPath的控件联系起来。 在我的例子中查询操作是由button控件的”Rules“完成的。 所有,有三件事情需要button控件去做: 为表Web Service的参数赋值;查询; 获得返回参数;

clip_image010

9. 为button控件添加三个Rules;

clip_image012

a. Set a field’s Value: Field: accountName; Value: UserName

b. Query for Data:

c. Set a field’s value: Field: Department; Value: Value

10. 保存模板。

11. 你可以预览或者发布到SharePoint的表单库进行测试。

 

请确保当前的应用程序”没有启用匿名登录“否则,你将会得到如下的错误” Server was unable to process request. ---> Attempted to perform an unauthorized operation.”

clip_image014

Good luck.

posted @ 2011-03-14 20:13  范文轩  阅读(2268)  评论(0编辑  收藏  举报