Connect InfoPath form to web service and deploy it to SharePoint


In this article I am describing about the Taking Advantage of XML Form Web Part in SharePoint and office InfoPath form which is an XML form Builder. This article will give the steps and configuration to be followed to access a web service in InfoPath 2007.

To Connect InfoPath to web service and make connected string Registered in Data Connect Library (DCL) in SharePoint please follow the below steps

Open InfoPath form Template

Open InfoPath form Template

Select Blank Form Template

Open InfoPath form Template

To select Data Connection Click Tools->Data Connections

Open InfoPath form Template

Click Add on Data Connection Window and data connection Wizard window will open as shown below image

Data Connection Window and data connection Wizard

Select Submit data or Receive data depend on the connection you need from web service and Click on next. Select the type Data source you need to connect in this project we are connecting to web service .click on next after selecting data source it.

Data Connection Window and data connection Wizard

In the next window we can type the Web Service Details

Connect InfoPath form to web service

Click Next ,it will list all methods in the Web service so select the web method for which we need to make connection

Connect InfoPath form to web service

If the Web Methods has Arguments to pass the following window will appear

Connect InfoPath form to web service

Click Next

Connect InfoPath form to web service

By Check in automatically retrieve data when form is opened then the form will Query the Data Source On Load of Form.

Connect InfoPath form to web service

By clicking Finish we have created Data Connection.

InfpSharp11.gif

With the Data Connections dialog box still open, click on the Convert button. This will open Convert Data Connection wizard.

InfpSharp12.gif

Specify the DCL Path With File Name same as the Data connection and Choose the connection link type to be "Relative to site collection (recommended)". Click Ok.



As you can see approval is by default active in any Data Connection Library which is created at the site collection level. This is a great way for site collection administrators to control existing data connection and approving them , before they can be used in any of the forms published to the site collection. Choose Approve/reject from the drop down menu for the new data connection as shown in the picture below. Choose Approved and click the OK button.InfpSharp13.gif
There is one extra step required to complete this section. When you access a web service from a browser-enabled InfoPath form, from Internet Explorer's standpoint this is a cross-domain connection and is not permitted unless the end user authorizes it. Unfortunately, HTTP is a stateless protocol so browser-enabled InfoPath form (running in a browser) is unable to stop the server-side code execution of the form in order to prompt the user to authorize the cross-domain call.

Running a form in Full trust bypasses this security check , but for all other security modes this security check is always performed. Thankfully, this behavior doesn't happen when you open the form in InfoPath client , so for browser-enabled forms that do not run in full trust mode and there is one or more Web service connections , you need to ask the farm's administrator to allow such connections to be made. Here are the steps:

  1. Go to SharePoint Central Admin Site
  2. Select Application Management tab
  3. In the InfoPath Forms Services section, choose Configure InfoPath Forms Services.
  4. Check "Allow cross domain access for user templates".

InfpSharp14.gif

Create a Data Connection Library

As mentioned above, we need a central location to store data connections associated with InfoPath forms. We can either convert the data connections (the ones that need to be converted) to UDC files in a Data Connection library located relatively to the site collection or we can put the whole process in the hand of the farm administrator to deal with our form's deployment process

  1. Click on Site Actions
  2. Choose View All Site Content
  3. Click on the Create button
  4. From the Libraries section choose Data Connection Library

InfpSharp15.gif

Register Data Connection in SharePoint Data Connection library (DCL)

By introducing Data Connection libraries and Universal Data Connections files (a.k.a UDC file) in MOSS 2007, Microsoft took the reusability goal to the next level. Data Connection libraries were designed with one primary objective: to abstract data connection settings in UDC files from the form template and store it in a location either relative to the root of the site collection or in a central location in Central administration site as shown.

Advantage of this level of abstraction is reusability. Technically speaking, data Connection library gives you the ability to share the same connection settings across multiple InfoPath forms, site collections or even Web applications when stored in the central administration site. Another benefit is that UDC files can be further customized based on your dev, staging or production environments which in turn means that instead of changing your form template every time you move your InfoPath forms from one environment to another one, all you need to do is to change the settings in a UDC file to match with the new environment configurations and that's it. Content types are yet another way in which InfoPath forms and SharePoint play very well together. Instead of attaching your form to a specific form library and do it over and over again for other form libraries, you can attach the form template to a content type and reuse it all across your site collection. As matter of fact, reusability is just the most obvious challenge that content types are supposed to solve in the new version of SharePoint; therefore InfoPath is just benefiting from such capability introduced by content types.

With a tighter integration with MOSS 2007, InfoPath forms offer way more than being just a rich and smart presentation layer on the top of MOSS 2007. InfoPath Forms Services feature of MOSS 2007 makes InfoPath also a browser-based, thin-client solution which allows users to interact with the forms through browser with absolutely no need for client application to be present on users' machines. Pretty much like any document libraries, in form libraries you have the option to set the forms to render either in InfoPath client or as a Web page in the browser. I will explain the about browser enabled form in my next article